1.4.2 For Loops
Last updated
Last updated
Basic for loops are the same as Java:
The for
loop initializes a value, then loops while the boolean expression is true. Each time through the loop, the loop variable takes on a new value.
The boolean expression gets evaluated after the loop variable is first initialized and then each cycle after the variable increments. Once inside the block of statements, the block will continue to execute even if the loop variable changes and the boolean expression is no longer true.
Many for loops are designed to start at zero and increment up by 1 each time. For loops are a lot more versatile than this though.
For loops can start, stop, and increment with any value. Here are a few other examples: