For Loop


Prev Tutorial Next Tutorial

For Loop in C++

When you need to execute a block of code several number of times then you need to use looping concept in C++ language. In C++ Programming Language for loop is a statement which allows code to be repeatedly executed. For loop contains 3 parts.

  • Initialization
  • Condition
  • Increment or Decrements


for ( initialization; condition; increment )
For Loop
  • Initialization: step is execute first and this is execute only once when we are entering into the loop first time. This step is allow to declare and initialize any loop control variables.
  • Condition: is next step after initialization step, 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 goes outside the for loop.
  • Increment or Decrements: After completion of Initialization and Condition steps loop body code is executed and then Increment or Decrements steps is execute. This statement allows to update any loop control variables.

Note: In for loop everything is optional but mandatory to place 2 semicolons (; ;)


for()	    // Error
for( ; ; )  // valid

Flow Diagram

For Loop

Control flow of for loop

control flow for loop
  • First initialize the variable
  • In second step check condition
  • In third step control goes inside loop body and execute.
  • At last increase the value of variable
  • Same process is repeat until condition not false.

Example of for loop


void main()
int i;



Important Points

  1. In for loop if condition part is not given then it will repeats infinite times, because condition part will replace it non-zero. So it is always true like.
    for( ; 1; )
  2. For loop is repeats in anti lock wise direction.
  3. In for loop also rechecking process will be occurred that is before execution of the statement block, condition part will evaluated.


while(0)	// no repetition
for( ; 0; )	// it will repeats 1 time

Note: Always execution process of for loop is faster than while loop.

Prev Tutorial Next Tutorial


Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: or 9999595223

wifi cctv camera

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements

Buy Websites 9999595223
wifi cctv camera

Wifi CCTV Camera RS:1200 to 2499.

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: or 9999595223 Try this Keyword C++ Programs