while
execute? 3while
statement
Here is the syntax for the while
statement:
while ( condition ) statement
Notes:
Since the statement can be a single statement or
a block statement,
a while
statement looks like
either choice in the table.
Almost always, though, a while
statement is used
with a block.
The style of indenting used here leads to
fewer errors than alternative styles.
The statements controlled by the while
are
indented.
The braces of the block are aligned with each other
and with the while
and each is put on its own line.
Varieties of while Statements | |
---|---|
while ( condition ) statement; |
while ( condition ) { one or more statements } |
Is the condition always surrounded by parentheses?