The for Loop Statement
As we have seen in many previous examples involving iteration, the three key components of a loop are as follows:
Loop condition— When evaluated to true, will cause the loop body to be repeated.
Loop initialization— During the loop initialization the variable(s) taking part in the loop condition are assigned initial suitable values. This process only takes place once before the loop commences.
Loop update— Updates the variables of the loop condition. This is repeatedly done during every loop.
These are exemplified in Figure 9.6, which uses the source code of the while loop shown earlier. Notice that only the loop condition is restrained by the rules of syntax to a specific position, namely inside a pair of parentheses positioned ...
Get C# Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.