Confusing Loops

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

Answer:

Yes. Deciding which way you want to do it is part of coordinating the three parts of a counting loop. It is easy to get confused about this.

Confusing Loops

Look at the following program fragment:

int count     = 13;
int decrement = -1;
while ( count >= 0 )   // GREATER-than-or-equal operator
{
  System.out.println( "count is:" + count );
  count = count - decrement;
}
System.out.println( "Count was " + count + " when it failed the test");

Look over each of the three parts of the counting loop.

QUESTION 8:

What will this program fragment print when it is run?