4.3.For loop #

For loop has rules that equivalent to while loop. For instance, it checks the condition(s) when it’s true it will process a statement and it will end the process when the condition(s) is false, but it’s easier 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