Counting Down

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:

21

Counting Down

Recall the general form of a for:

for ( initialize ; test ; change )
  loopBody ;

The change can be any statement. It can, for example, decrease the control variable, as in this example:

    for ( count = 10; count >= 0; --count  )  
    {
      System.out.println( "count is: " + count ); 
    }
    System.out.println( "/nDone with the loop./nCount is now" + count);

Here is a Javascript version of the program fragment:


 

QUESTION 10:

Would the output of this program be any different if the expression --count were changed to count--   ?