Yes — there is the if
statement
(both with and without an else
),
the switch
statement,
and the conditional
statement.
Of these, the if
statement is
by far the most useful.
do
Statement
The do
statement is similar to the
while
statement with an important
difference: the do
statement performs a
test after each execution of the loop body.
Here is a counting loop that prints integers from 1 to 9:
int count = 0; // initialize count to 0 do { System.out.println( count ); // loop body: includes code to count++ ; // change the count } while ( count < 10 ); // test if the loop body should be // executed again.
Notice how the do
and the
while
bracket the statements
that form the loop body.
The condition that is tested follows the while
.
Does the code fragment include the three things that all loops must do?