Active For 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:

Just above the test part of a loop. This is were for loops automatically put it, and where it is sensible to put it if you are implementing a loop with a while.

Active For Loop

Here is another example. Notice that the loop body is a block statement although there is only one statement nested inside the block. This is syntactically correct.

int count;
for ( count = 0; count < 7; count++ )  
{
  System.out.println( "count is: " + count ); 
}
System.out.println( "Done with the loop" );

Here is a JavaScript version of this loop. Try to predict what it will output:




 

QUESTION 6:

Do you think that the change part of the for statement must always increment by one?