Introducing the for Loop

Tips/C++ Eng2015.11.04 00:41

The for loop executes a block of code repeatedly until the specified expression evaluates to false. You can define a for loop as follows.

for ([initializer(s)]; [condition]; [iterator]) 
   // code to repeat goes here

The [initializer(s)] portion is used to initialize a value, or values, as a counter for the loop. On each iteration, the loop checks that the value of the counter is within the range to execute the for loop, specified 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 for incrementing the loop counter.

The following code example shows how to use a for loop to execute a code block 10 times.

for Loop
for (int i = 0 ; i < 10; i++) 
    // Code to execute.
In this example, i = 0; is the initializer, i < 10; is the condition, and i++ is the iterator. 

This contents come from edx : Introduction to C++

'Tips > C++ Eng' 카테고리의 다른 글

Introducing Classes  (0) 2015.11.28
Storage classes and Scope  (0) 2015.11.23
Introducing the for Loop  (0) 2015.11.04
The Conditional (Ternary : 3중 조건문)  (0) 2015.11.04
switch Statments  (0) 2015.11.04
Introducing Operators  (0) 2015.11.01


Posted by 비타오백

관련 글

댓글 영역

티스토리 툴바