C++ For loop

Facebooktwitterredditpinterestlinkedinmailby feather

C++ loop Statement

C++ Loop statement allows us to repeat the execution of a statement or group of statements multiple times. The statement(s) repeat execution within loop until the condition of loop became false.

There are three types of loops in C++ programming language:

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

for loop C++ Flow Chart

C++ for Loop Statement

The for loop is an iterative control statement. It executes loop’s statement(s) several times until the condition of for loop become false.


Working Process of for loop

  1. The initialize expression statement is executed only once and initialize variable expr.
  2. Then condition expression checks the condition applied, if it satisfies (true), statement(s) inside for loop executes otherwise execution exit from for loop.
  3. After statement(s) execution within for loop block, it update the variable expr and repeat step 2.

C++ For Loop Flow Chart

C++ for Loop Example

This example print counting from 1 to 10.


Infinite for Loop

Infinite for loop repeats the loop block infinite times. This happens when condition statement of for loop always true (never false).

Infinite loop in C++ programming language is terminated using shortcut keys Ctrl + C.


Infinite for loop Example


Print counting from 1 to infinite.

Facebooktwitterredditpinterestlinkedinmailby feather

Leave a Comment