Java uses sequence, selection, and repetition structures to control program flow. The sequence structure executes statements in the order written unless otherwise specified. Selection statements include if, if/else, and switch statements to select or skip actions based on conditions. Repetition statements like while, do/while, and for loops repeatedly execute actions as long as a condition remains true. These control structures use keywords like if, else, switch, while, do and for that cannot be reassigned as identifiers.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
699 views
Sequence Structure in Java
Java uses sequence, selection, and repetition structures to control program flow. The sequence structure executes statements in the order written unless otherwise specified. Selection statements include if, if/else, and switch statements to select or skip actions based on conditions. Repetition statements like while, do/while, and for loops repeatedly execute actions as long as a condition remains true. These control structures use keywords like if, else, switch, while, do and for that cannot be reassigned as identifiers.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1
Sequence Structure in Java
The sequence structure is built into Java. Unless directed otherwise, the computer executes Java statements one after the other in the order in which they are written—that is, in sequence.
Selection Statements in Java
Java has three types of selection statements (discussed in this chapter and Chapter 5). The if statement either performs (selects) an action, if a condition is true, or skips it, if the condition is false. The if…else statement performs an action if a condition is true and performs a different action if the condition is false. The switch statement (Chapter 5) performs one of many different actions, depending on the value of an expression. The if statement is a single-selection statement because it selects or ignores a single action (or, as we will soon see, a single group of actions). The if…else statement is called a double-selection statement because it selects between two different actions (or groups of actions). The switch statement is called a multiple-selection statement because it selects among many different actions (or groups of actions).
Repetition Statements in Java
Java provides three repetition statements (also called looping statements) that enable programs to perform statements repeatedly as long as a condition (called the loop-continuation condition) remains true. The repetition statements are the while, do…while and for statements. (Chapter 5 presents the do…while and for statements.) The while and for statements perform the action (or group of actions) in their bodies zero or more time if the loop-continuation condition is initially false, the action (or group of actions) will not execute. The do…while statement performs the action (or group of actions) in its body one or more times. The words if, else, switch, while, do and for are Java keywords . Recall that keywords are used to implement various Java features, such as control statements. Keywords cannot be used as identifiers, such as variable names.