Home For loop
Post
Cancel

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
using namespace std;
int main()
{
    int i;
    for(i=1;i<10;i++)
    {
        cout<<i<<' ';
    }
    return 0;
}

OUTPUT:

output

This post is licensed under CC BY 4.0 by the author.

Trending Tags