Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Iterative Statements Concepts Covered: Iterative Statements (counter-based) Iterative.

Similar presentations


Presentation on theme: "COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Iterative Statements Concepts Covered: Iterative Statements (counter-based) Iterative."— Presentation transcript:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

16 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 16 “Real Life” Application of Nested Loops

17 COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 17 Design Choices Counter vs. Sentinel Early Test  [0:N] iterations Late Test  [1:N] iterations Conditional Infinite loops (e.g. counter based) Summary on using loops


Download ppt "COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Iterative Statements Concepts Covered: Iterative Statements (counter-based) Iterative."

Similar presentations


Ads by Google