May 2002
Beginner
320 pages
6h 18m
English
The for loop combines three parts—initialization, condition, and step—into one statement at the top of the block it controls. A for statement has the following form:
for (initialization; condition; step) { statements; } ;
The first part of the for statement is the initialization. Any legal C++ statements can be put here (separated by commas), but typically this is used to create and initialize an index variable. Such a variable is most commonly an int. This part ends with a semicolon and is only performed once before the loop starts.
Next is the condition, which can be any legal C++ bool expression. This serves the same role as the condition in the while loop and should be read as “while Index is less than myNumberOfEntries” in ...
Read now
Unlock full access