Boundary Conditions

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

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:

  • Look at the initialization.
  • Look at the condition to determine when the loop ends.
  • Look at what change is made each time the loop body executes.

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?