For Statement

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, it certainly would.

For Statement

Java has a for statement which combines all three aspects of a loop. It looks like this:

for ( initialize ; test ; change )
  loopBody ;

The initialize, test , and change are expressions that (usually) perform the named action. The loopBody can be a single statement or a block statement. Here is an example of a for statement:

//   initialize;     test;     change
//
for ( count = 0;  count < 10; count++ )
  System.out.print( count + " " );

It does the same thing as this loop built using a while statement:

count = 0;                             // initialize
while (  count < 10 )                  // test
{
  System.out.print( count + " ");
  count++ ;                            // change
}

The variable count in both loops is the loop control variable. (A loop control variable is an ordinary variable used to control the actions of a looping structure.) Remember that count++ has the same effect as count = count + 1.

QUESTION 3:

What is the output of both loops?