For Loop in C++ programming is a control flow statement that allows code to be repeatedly executed and repeat a specific block of code for a fixed number of times.
for(initialise counter; test counter; increment counter)
{
do this;
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
for(a = 0; a <= 10; a++) //loop looping from 0 to 10.
{
cout<<a<<endl; //and printing.
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
for(int a = 0; a <= 10; a++) //loop looping from 0 to 10.
{
if(a > 4 && a < 8) //if 'a' value greater then 4 And less then 8 then
{
cout<<a<<endl; //print 'a' value.
}
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
for(int a = 0; a <= 10; a++) //loop looping from 0 to 10.
{
if(a == 5) //if 'a' value Equal to 5 then
{
cout<<"The Statement is Break on 5!";
break; //break Statement.
}
cout<<a<<endl;
}
getch();
}