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.
1. The Fantastic For Statement
The
for statement is a convenient way to program counting loops. It also can be used to build all three types of loops. Anything it does could also be done with the fundamental control statements you already know. But the for statement
often says just what you want in a compact, easily understood format.Chapter Topics:
- The three parts of all loops (review)
- Syntax of the
forstatement - Using the
forstatement in counting loops - Equivalence of
forandwhileloops
Question 1:
What are the three types of loops?
Source: Bradley Kjell, http://programmedlessons.org/Java9/chap24/ch24_01.html
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 License.