count = count + 1;

A good answer might be:

It increases count by one.

If this is not clear remember the two steps of an assignment statement: first evaluate the expression on the right of the equal sign, second put the value in whatever variable is on the left. Say that count is 5. When the above statement executes, first the expression is evaluated, resulting in 6. Second the 6 is put in count.


How the while Loop Works

Here the part of the program responsible for the loop:

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" );

Here is how it works:

  1. The variable count is assigned a 1.
  2. The condition ( count <= 3 ) is evaluated as true.
  3. Because the condition is true, the block statement following the while is executed.
    • The current value of count is written out:    count is 1
    • count is incremented by one, to 2.

  4. The condition ( count <= 3 ) is evaluated as true.
  5. Because the condition is true, the block statement following the while is executed.
    • The current value of count is written out.   count is 2
    • count is incremented by one, to 3.

  6. The condition ( count <= 3 ) is evaluated as true.
  7. Because the condition is true, the block statement following the while is executed.
    • The current value of count is written out.   count is 3
    • count is incremented by one, to 4.

  8. The condition ( count <= 3 ) is evaluated as FALSE.
  9. Because the condition is FALSE, the block statement following the while is SKIPPED.

  10. The statement after the entire while-structure is executed.
    • System.out.println( "Done with the loop" );

QUESTION 3:

  1. How many times was the condition true?
  2. How many times did the block statement following the while execute?