int count = 1; // count is initialized while ( count <= 3 ) // count is tested { System.out.println( "count is:" + count ); count = count + 1; // count is changed } System.out.println( "Done with the loop" );
Three activities of a loop must work together:
while
statement must be correct.In the above program we wanted to print the integers "1, 2, 3". Three parts of the program had to be coordinated for this to work correctly.
What will the program print if the initialization is changed as follows?
int count = 0; // count is initialized while ( count <= 3 ) // count is tested { System.out.println( "count is:" + count ); count = count + 1; // count is changed } System.out.println( "Done with the loop" );