For loop
There are three commands in for loop first setting the loop variable to an initial value,the second is a logical operation which specifies when the loop ends and the third is changing the value of loop variable after each iteration.First i
is intialized to 1,then it checks whether i
is less than 10.After that the code in the for loop is execute then value of i
is incremented by 1.The loop ends when i=10
.
#include<iostream>
using namespace std;
int main()
{
int i;
for(i=1;i<10;i++)
{
cout<<i<<' ';
}
return 0;
}
OUTPUT: