19
Iteration Statement Made by Gaurav Yadav XI-A Roll No- 10

Iteration Statement in C++

Embed Size (px)

Citation preview

Page 1: Iteration Statement in C++

Iteration Statement Made byGaurav YadavXI-ARoll No- 10

Page 2: Iteration Statement in C++

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

Page 3: Iteration Statement in C++

ELEMNTS THAT CONTROL

A LOOP

InitializationExpression

Test Expression

UpdateExpression

The Body Of The Loop

Page 4: Iteration Statement in C++

Click icon to add picture

Click icon to add picture

Type offor

Loop

while Loop

Do while Loop

Page 5: Iteration Statement in C++

The for Loop

Page 6: Iteration Statement in C++

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;

}

Page 7: Iteration Statement in C++

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

Page 8: Iteration Statement in C++

Example

• Output• Input

Page 9: Iteration Statement in C++

The while Loop

Page 10: Iteration Statement in C++

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

Page 11: Iteration Statement in C++

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

Page 12: Iteration Statement in C++

Example

Input Output

Page 13: Iteration Statement in C++

The do-while Loop

Page 14: Iteration Statement in C++

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)

Page 15: Iteration Statement in C++

Flow Chart

Page 16: Iteration Statement in C++

Example

Input Output

Page 17: Iteration Statement in C++

Iteration Do’s

Page 18: Iteration Statement in C++
Page 19: Iteration Statement in C++