O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The for Loop

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required