2. Iteration Statements
■ Used to iterate or re-use a set of instructions
■ Saves programming time
■ Reduce number of lines of code
■ Ultimately makes a program more efficient
Iteration
Statements
For Loop While Loop
Do-While
Loop
3. Iteration Statements
■ Iteration Statements have three part:
– Initialization
– Condition
– Increment/Decrement
Initialization: Initializes the loop variable.
Condition: The loop will execute till the condition is met.
Increment/Decrement: It alters the value of the loop variable.
4. FOR Loop
■ It is a entry control loop i.e. the condition is checked before executing the loop
statements
■ It is used to iterate a set of lines/instructions
■ Initialization, Condition and Increment/Decrement all resides together at the top of
the statement
■ Mostly used while working with arrays or while printing some patterns
5. FOR loop – SYNTAX
for ( initialization; condition; increment_or_decrement )
{
//Set of instructions to be iterated
}
6. Different cases in FOR loop
1. If increment/decrement or condition is missing from the loop, It will run infinitely
2. Initialization can be done outside (above) the loop too.
7. Different cases in FOR loop
3. Another way to start infinite loop
4. Semicolon in front of for loop statement: Loop executes but didn’t take any
statements under it. i.e. Empty loop will run