Answer:

10 times

More on the while Loop

Here is 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 in tedious detail. Look especially at steps 7, 8, and 9.

  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 4:

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