The For Statement

The 'for' loop is more compact than the 'while' and 'do' loops and automatically updates the loop counter at the end of each iteration. Both 'for' and 'while' loops are designed for different situations. You'll learn more about when to use each later.

12. Omitting the change



Omitting the change

Syntactically you can omit the change part. This means that if the Java compiler sees:

for ( count = 0; count < 25;  )

it will not complain. It is now your responsibility to put statements that make a change somewhere into the loop body. For example:

for ( count = 0; count < 25;  )
System.out.println("count is: " + count );
count = count + 1;

would work fine. (Although in this case it would be far better to do the change in the for.)

Question 12:

Can a for statement be used to implement a sentinel controlled loop?