Iterative Statements Part 1 Module 3 Concepts Covered
















![Summary on using loops Design Choices Counter vs. Sentinel Early Test [0: N] iterations Summary on using loops Design Choices Counter vs. Sentinel Early Test [0: N] iterations](https://slidetodoc.com/presentation_image_h/0963cc5424aeb25e4f38a0e669181979/image-17.jpg)
- Slides: 17

Iterative Statements Part 1 Module 3 Concepts Covered: Iterative Statements (counter-based) Iterative Statements (sentinel-based) Serially Arranged Nested BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 1

Iterative Statements Concept: Iterative Statements (counter-based) BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 2

Counter = 1 Counter-based Iteration LOOP Do some work Counter = Counter +1 YES TRUE Is Counter == 10 ? NO FALSE Some more work To do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 3

Counter = 1 Counter-based Iteration Late Test LOOP Do some work Counter = Counter +1 YES TRUE Is Counter == 10 ? NO FALSE Some more work To do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 4

Counter = 1 Counter-based Iteration Early Test LOOP YES TRUE Is Counter == 10 ? NO FALSE Do some work Counter = Counter +1 Some more work To do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 5

Counter-based Iteration middle Test Counter = 1 LOOP Counter = Counter +1 Is Counter == 10 ? Do some work Some more work To do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 6

Iterative Statements Concept: Iterative Statements (sentinel-based) BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 7

Sentinel-based Iteration LOOP Do some work Display: “one more? ” Read: RESPONSE is “no” Some more work To do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 8

Sentinel-based Iteration Late Test LOOP Do some work Display: “one more? ” Read: RESPONSE is “no” Some more work To do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 9

Iteration (both kind) Early Test Display: “one more? ” Read: RESPONSE LOOP RESPONSE is “no” Do some work Display: “one more? ” Read: RESPONSE Some more work To do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 10

Iteration (both kind) Middle Test LOOP Display: “one more? ” Read: RESPONSE is “no” Do some work Some more work To do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 11

Iterative Statements Concept: Serially Arranged Iterative Statements BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 12

Two separate loops one after the other LOOP Display: “one more? ” Read: RESPONSE is “no” Do some work Do more some work BSAS Industrial Operations COP 2510 Programming Concepts Some more work to do after the loop Alessio Gaspar 13

Iterative Statements Concept: Nested Iterative Statements BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 14

Two nested loops one inside another LOOP Display: “one more? ” Read: RESPONSE is “no” Inner Loop Do more some work Some more work to do after the loop BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 15

“Real Life” Application of Nested Loops BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 16
![Summary on using loops Design Choices Counter vs Sentinel Early Test 0 N iterations Summary on using loops Design Choices Counter vs. Sentinel Early Test [0: N] iterations](https://slidetodoc.com/presentation_image_h/0963cc5424aeb25e4f38a0e669181979/image-17.jpg)
Summary on using loops Design Choices Counter vs. Sentinel Early Test [0: N] iterations Late Test [1: N] iterations Conditional Infinite loops (e. g. counter based) BSAS Industrial Operations COP 2510 Programming Concepts Alessio Gaspar 17