go to previous page   go to home page   go to next page hear noise

Answer:

Yes.


Semantics of the while statement

Here is the while statement, again:

while ( condition )
  loop body            // a statement or block statement

statement after the loop

Here is how the while statement works. In the following, the word control means "the statement that is executing".

Here is the while loop from the example program:


int count = 1;                                  // start count out at one
while ( count <= 3)                             // loop while count is <= 3
{
  System.out.println( "count is:" + count );
  count = count + 1;                            // add one to count
}
System.out.println( "Done with the loop" );     // statement after the loop


This loop uses the variable count. It is started out at 1, then incremented each time the loop body is executed until it reaches 4 and the condition is false. Then the statement after the loop is executed.


QUESTION 6:

The variable count is used in three different activities. It is initialized, tested, and changed. Where in the program does each of these events take place?