View
381
Download
0
Embed Size (px)
Citation preview
Iteration Statement Made byGaurav YadavXI-ARoll No- 10
What is Iteration?
Iteration construct means repetition of set of statements depending upon a condition test. Till the time of condition is true. ( or false depending upon the loop). A set of statements are repeated again and again. As soon as the condition become false (or true), the repetition stops. The iteration condition is also called ”Looping Statement ”.
Idli
ELEMNTS THAT CONTROL
A LOOP
InitializationExpression
Test Expression
UpdateExpression
The Body Of The Loop
Click icon to add picture
Click icon to add picture
Type offor
Loop
while Loop
Do while Loop
The for Loop
The for Loop
• In computer science a for-loop (or simply for loop) is a programming language control statement for specifying iteration, which allows code to be executed repeatedly.
• Syntax
for (ForInit ; ForExpression; PostExpression)
Action
• Example
for (int i = 0; i < 3; ++i) { cout << "i is " << i << endl;
}
FlowChartForA
for-Loop
ForExpr
Action
true false
ForInit
PostExpr
Evaluated onceat the beginning
of the forstatements's
execution The ForExpr isevaluated at thestart of each
iteration of theloop
If ForExpr istrue, Action is
executed
After the Actionhas completed,
thePostExpression
is evaluated
If ForExpr isfalse, program
executioncontinues withnext statement
After evaluating thePostExpression, the next
iteration of the loop starts
Example
• Output• Input
The while Loop
The while Loop
• In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement.
• Syntax
Logical expression that determineswhether the action is to be executed
while ( Expression ) Action
Action to be iterativelyperformed until logical
expression is false
FlowChartOfAwhileLoop
Expression
Action
true false
Expression isevaluated at the
start of eachiteration of the
loop
If Expression istrue, Action is
executed If Expression isfalse, program
executioncontinues withnext statement
Example
Input Output
The do-while Loop
The do-while Loop
• a do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block.
• Syntax
do Action
while (Expression)
Flow Chart
Example
Input Output
Iteration Do’s