elibraryportal Logo

Iteration Statement or Loops in C++

The statements that cause a set of statements to be executed repeatedly either for a specific number of times or until some condition is satisfied are known as iteratio statements.

Types of Iteration statements

  1. for loop
  2. while loop
  3. do-while loop

For Loop Statement in C++

In for loop is a repetition control structure part that allows you to efficiently write a loop that needs to execute a specific number of times.

OR

for loops are used to execute a set of statements repeatedly until a particular condition is satisfied.

Syntax:-

C++ Example

Output:

1
2
3
4
5

Nested For Loop in C++

We can use for loop inside another for loop, it is known as nested for loop.

Nested For Loop Example :- Print a 2D matrix of 3×3.

Output:

123
456
789

Nested For Loop Example :-

Output:

Enter Number :  5
*  
*  *  
*  *  *  
*  *  *  *  
*  *  *  *  *