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

What will the program print if the initialization is changed to:

int count = 0;

Answer:

count is 0
count is 1
count is 2
count is 3
Done with the loop

Boundary Conditions

To determine what a loop does, look at the following:

Sometimes these are called boundary conditions because they occur at the boundaries of the loop body and greatly affect what the loop does. The name "boundary condition" is an analogy to mathematics, where how a mathematical function behaves depends on its values at the boundaries of an interval.

Here is another version of the example fragment:

int count = 1;  
while ( count < 4 )  // this is different 
{
  System.out.println( "count is:" + count );
  count = count + 1;   
}
System.out.println( "Done with the loop" );      

The loop condition has been changed from the previous version.


QUESTION 8:

What does the program print out?


go to previous page   go to home page   go to next page