5.3.For loop

For loop has a rule same of while loop, checking condition then process a statement when it’s true and end process when condition false, but it has an easy way to use than while loop.
Syntax:

for( initialization ; condition ,iteration )
{
	Statement;
}

Example 1:

#include<iostream.h>
#include<conio.h>
void main()
{
        int n;
        cout<<"Enter N: "; cin>>n;
        for(int i=n;i>0;i--)
        {
    	        cout<<i<<" ";
        }
	getch();
}

Example 2:

#include<iostream.h>
#include<conio.h>
void main()
{
	for(int i=1;i<=10;i++)
	{
		cout<<"2"<<"*"<<i<<"="<<2*i<<endl;
	}
	getch();
}

Suggest Edit