Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Iteration Statements (C++)

Iteration statements cause statements (or compound statements) to be executed zero or more times, subject to some loop-termination criteria. When these statements are compound statements, they are executed in order, except when either the break statement or the continue statement is encountered.

C++ provides three iteration statements — while, do, and for. Each of these iterates until its termination expression evaluates to zero (false), or until loop termination is forced with a break statement. The following table summarizes these statements and their actions; each is discussed in detail in the sections that follow.

Iteration Statements
Statement Evaluated At Initialization Increment

while

Top of loop

No

No

do

Bottom of loop

No

No

for

Top of loop

Yes

Yes

The statement part of an iteration statement cannot be a declaration. However, it can be a compound statement containing a declaration.

Community Additions

ADD
Show:
© 2015 Microsoft