‹ back to Programming C++

NotesProgramming C++ · 3 January 2016

For loop 1

A for loop is a is a sequential control command that is often use for repetition , for a specific number of times

The Syntax

for(variable ; condition ; increment/decrement)

1. the variable declares the loop initialization process , it help us to declare

2. The condition is the state which tell us either the loop should be executed or not. if the condition is true, it will keep on running , unless the condition becomes false.

3. The increment/decrement is the mathematical part, which changes after

every loop.

For Loop First Program

#include<iostream>

using namespace std;

main()

{

cout<<“My First C++ Program”<<endl;

for(int i=0;i<=5;i++)

cout<<i<<endl;

}

Lets try to understand what is happening

First Iteration

Second Iteration

Third Iteration

Fourth Iteration

Fifth Iteration

As soon as the loop condition becomes falls , the program stops executing the for loop

First published on fatsup.wordpress.com ↗