You are on page 1of 2

4/23/2017 for Loops | Repetition Statements | DEV210x Courseware | edX

Microsoft: DEV210x Introduction to C++ Help

Module 3 Control Statements > Repetition Statements > for Loops



Bookmarks
for Loops
 Bookmark this page
 Module 0

The for loop executes a block of code repeatedly until the specified
 Module 1
expression evaluates to false. You can define a for loop as follows.
Introducing
C++
for ([initializer(s)]; [condition]; [iterator]) 
{
 Module 2 Data
   // code to repeat goes here
Types in C++
}

 Module 3
The [initializer(s)] portion is used to initialize a value, or values,
Control
as a counter for the loop. On each iteration, the loop checks that the
Statements
value of the counter is within the range to execute the for loop, specified
C++ Operators in the [condition] portion., and if so, execute the body of the loop.   At
then end of each loop iteration, the [iterator] section is responsible
Decision
Statements
for incrementing the loop counter.
Self-Check 

The following code example shows how to use a for loop to execute a
Repetition
Statements code block 10 times.
Self-Check 

Peer Review for Loop


Homework  for (int i = 0 ; i < 10; i++) 
{
 Module 4     // Code to execute.
Functions and }
Objects In this example, i = 0; is the initializer, i < 10; is the condition, and
i++ is the iterator.
 End of Course
Evaluation

© All Rights Reserved

https://courses.edx.org/courses/course­v1:Microsoft+DEV210x+2T2017/courseware/bfc4cb492f3241a3891a98587ddfb849/d4c37651971a4651809b018ecd4f99b2/ 1/2
4/23/2017 for Loops | Repetition Statements | DEV210x Courseware | edX

© 2012-2017 edX Inc. All rights reserved except where noted. EdX, Open edX and the edX and Open EdX logos
are registered trademarks or trademarks of edX Inc.

     

https://courses.edx.org/courses/course­v1:Microsoft+DEV210x+2T2017/courseware/bfc4cb492f3241a3891a98587ddfb849/d4c37651971a4651809b018ecd4f99b2/ 2/2

You might also like