Difference between revisions of "W1154 For Loop"

From Coder Merlin
Line 9: Line 9:


== For Loops ==
== For Loops ==
''for loops'' execute for a defined count of iterations, as such, the ''test condition'' is implied within the definition.  Through each iteration, a ''loop control variable'' is adjusted toward its final goal.  When that goal is reached, the loop exits.
''for loops'' execute for a defined count of iterations, as such, the ''test condition'' is implied within the definition.  Through each iteration, a ''loop control variable'' is adjusted toward its final goal.  When that goal is reached, the loop exits. '''The actual implementation is identical to that of a ''while loop''.'''


== Key Concepts ==
== Key Concepts ==
== Exercises ==
== Exercises ==
== References ==
== References ==

Revision as of 21:12, 16 January 2020

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Roller Coaster Loop

Prerequisites[edit]

Introduction[edit]

The for loop is a construct which enables us to execute a segment of code a defined number of times. It is thus the most appropriate choice when we know in advance how to calculate the number of iterations prior to beginning the loop. While this construct is not strictly necessary, it provides syntactic sugar by clarifying intent.

For Loops[edit]

for loops execute for a defined count of iterations, as such, the test condition is implied within the definition. Through each iteration, a loop control variable is adjusted toward its final goal. When that goal is reached, the loop exits. The actual implementation is identical to that of a while loop.

Key Concepts[edit]

Exercises[edit]

References[edit]