For Loop In C++

Card image cap

For Loop ?

Loops are used in programming to repeat a specific block until some end condition is met. There are three type of loops in C++ programming.


How for loop works?

The initialization statement is executed only once at the beginning.

Then, the test expression is evaluated.

If the test expression is false, for loop is terminated. But if the test expression is true, codes inside body of for loop is executed

Again, the test expression is evaluated and this process repeats until the test expression is false.

Syntax :

for ( init; condition; increment ) {
   statement(s);
   }
Card image cap

Example 1:



Output :

aimtocode
aimtocode
aimtocode
aimtocode
aimtocode
    
Card image cap

Example 2:



Output :

  aimtocode Roll No: 10
  aimtocode Roll No: 11
  aimtocode Roll No: 12
  aimtocode Roll No: 13
  aimtocode Roll No: 14
  aimtocode Roll No: 15
Card image cap