0% found this document useful (0 votes)
4 views2 pages

For (Initialisation Condition Increment/decrement) (Statement(s) )

The document explains the syntax of a for loop in programming, detailing its components: initialization, condition, and increment/decrement. It provides examples of using a for loop to count from 1 to 5 and to print even numbers from 1 to 20. Additionally, it includes an exercise for the user to create a program that displays odd numbers between two user-defined values.

Uploaded by

neha.ijaz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

For (Initialisation Condition Increment/decrement) (Statement(s) )

The document explains the syntax of a for loop in programming, detailing its components: initialization, condition, and increment/decrement. It provides examples of using a for loop to count from 1 to 5 and to print even numbers from 1 to 20. Additionally, it includes an exercise for the user to create a program that displays odd numbers between two user-defined values.

Uploaded by

neha.ijaz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like