10
Iteration Statements What you’ll learn: 1.while loop 2.do – while loop 3.for loop 4.Jump Statements

3.looping(iteration statements)

Embed Size (px)

Citation preview

Page 1: 3.looping(iteration statements)

Iteration Statements

What you’ll learn:

1.while loop

2.do – while loop

3.for loop

4.Jump Statements

Page 2: 3.looping(iteration statements)

What are iteration statements?

An iteration statement, or loop, is a way of repeating a statement, known as loop body, a number of times until some condition is satisfied.

We have following types of iteration statements in C: while loop

do-while loop

for loop

Set of instructions

conditionTrue

False

Page 3: 3.looping(iteration statements)

Iteration Statements

while loop

Page 4: 3.looping(iteration statements)

while loop

Syntax:

initialization;while (test_condition) {        ...block of code...        increment/decrement;}

loop bodyconditionTrue

False

exit from loop

instructions

Page 5: 3.looping(iteration statements)

Iteration Statements

do-while loop

Page 6: 3.looping(iteration statements)

do – while loop

Syntax:

initialization;do {

…block of code…increment/decrement;

} while (test_condition);

conditionTrue

Exit from loop

Loop body

False

Page 7: 3.looping(iteration statements)

Iteration Statements

for loop

Page 8: 3.looping(iteration statements)

for loop

Exit from loopconditionFalse

True

Loop body

initialization

Syntax:

for ( initialization; test_condition; update_expression ) {

…block of code…}

Update Expression

Page 9: 3.looping(iteration statements)

Jump Statements

What are jumping statements ?

Page 10: 3.looping(iteration statements)

What are jumping statements?

Jump statements can be used to modify the behavior of conditional and iterative statements.

Some jump statements provided by C are:o continueo breako gotoo return