For Loop C++ – Tutorialpath

Loops in C++

Loops in programming comes into use when we need to repeatedly execute a block of statements.

Syntax:

syntax of loops in c++
syntax of loops in c++

 

  • The init step is executed first, and only once. This step allows you to declare and initialize any For Loop C++ control variables. You are not required to put a statement here, as long as a semicolon appears.
  • Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement just after the for loop.
  • After the body of the for loop executes, the flow of control jumps back up to the increment statement. This statement can be left blank, as long as a semicolon appears after the condition.

The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the for loop terminates.

Flowchart of Loop in C++ :

loops
loops

 

Example:

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *