Syntax
for (initialisation;condition;increment/decrement)
Statement(s);
For example: for(x=1; x<=10;x++)
Initialisation-starting value of the counter variable
Condition- the loop is executed only if the condition is true
Increment/decrement- the change in counter variable
Exercise: Write a program that displays counting from 1-5 using for loop
Int main()
int n;
for(n=1; n<=5; n++)
cout<<n<<endl; }
return 0;
Exercise: Print even numbers from 1-20 using for loop
Int main()
for(int n=2; n<=20; n+=2)
cout<<n<<endl; }
return 0;
}
Exercise: Take starting and ending number from user and display odd numbers between them.