Infinite Loop

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:

count is 13
count is 14
count is 15
count is 16
count is 17
  . . . .
count is 678
count is 679
count is 680
  . . . . and so on without end

Infinite Loop

It is possible (and common) to accidently create a counting loop that never ends. In the above example, this happened because the variable decrement had the value minus one. So the statement

count = count - decrement;

actually added one to count. So count kept getting larger and larger, never reaching the zero that the condition part was looking for:

while ( count >= 0 )   // GREATER-than-or-equal operator

Such loops are called infinite loops, or non-terminating loops. It is easy to accidentally include them in a program. Here is another fragment:

int count  = 20;
int dec    = -1;
while ( count __________ 10 )   // what  relational operator ?
{
  System.out.println( "count is:" + count );
  count = count + dec ;
}
System.out.println( "count was " + count + " when it failed the test");

QUESTION 9:

What relational operator should be used so that the program fragment prints out the integers 20 down to and including 11 ?