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" );
There are three things to coordinate when your program has a loop:
while
statement must be correct.For example, in the above program we wanted the integers "1, 2, 3 " to be printed out. 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 in the following:
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" );