Break Goto Return Continue: While Do
Break Goto Return Continue: While Do
each of the statements within the block. The body of the loop (the
block of code) is enclosed in braces and indented for readability.
(The braces are not required if only ONE statement is used in the
body of the loop.)
A while loop can also terminate when a break, goto, or return within
the statement body is executed. Use continue to terminate the current
iteration without exiting the whileloop. continue passes control to
the next iteration of the while loop.
2.) Syntax:
4.) Syntax:
while(condition)
do
{
statement(s);
statement(s);
}while( condition );
3.) The do-while loop is similar to the while loop, except that the test
condition occurs at the end of the loop. Having the test condition at
the end, guarantees that the body of the loop always executes at least
one time. The format of the do-while loop is shown in the box at the
right.
Notice that the conditional expression appears at the end of the loop,
so the statement(s) in the loop execute once before the condition is
tested.