LEC 6:Loop Introduction| For loop 

Source code:

/*

There may be a situation, when you need to execute a block of code several number of times.

--1) for loop ,

--2) while loop ,

--3) do while loop ,

`-----------For loop: -----------------

Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.

-----synatx of for loop-------

for ( init; condition; increment )

 {

   statement(s);

}

*/

#include<iostream>

using namespace std;

int main()

{

    int n;

    cout<<"Enter the number";;

    cin>>n;

    for(int i=1;i<=n;i++) //i++ means increment i by 1

    {

            cout<<"\n"<<i;

    }

    return 0;

}


Comments

Popular posts from this blog

RunwayWithCode

web development Lectures

C++ Lectures