Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 8: More on the Repetition Structure

Similar presentations


Presentation on theme: "Chapter 8: More on the Repetition Structure"— Presentation transcript:

1 Chapter 8: More on the Repetition Structure
Introduction to Programming with C++ Fourth Edition

2 Objectives Show the posttest repetition structure in pseudocode and in a flowchart Code a posttest loop using the C++ do while statement Nest repetition structures Introduction to Programming with C++, Fourth Edition

3 Posttest Loops Condition is evaluated with each repetition, or iteration, of the loop Evaluation occurs after the instructions within the loop are processed Introduction to Programming with C++, Fourth Edition

4 Posttest Loops (continued)
Introduction to Programming with C++, Fourth Edition

5 Coding the Posttest Loop
In the do while statement, the programmer must supply the loop condition to be evaluated Loop condition: Must be a Boolean expression (true or false) Can contain variables, constants, functions, methods, arithmetic operators, comparison operators, and logical operators Introduction to Programming with C++, Fourth Edition

6 Coding the Posttest Loop (continued)
Programmer must also supply statements to be processed when the loop condition evaluates to true If more than one statement needs to be processed, they must be entered as a statement block Introduction to Programming with C++, Fourth Edition

7 Syntax of the C++ do while Statement
Introduction to Programming with C++, Fourth Edition

8 Nested Repetition Structures
Inner loop - placed entirely within another loop, called the outer loop Introduction to Programming with C++, Fourth Edition

9 Nested Loops Used by a Clock
Introduction to Programming with C++, Fourth Edition

10 Summary Posttest repetition structure evaluates a condition after the loop body Use the do while statement to code a posttest loop You can also use nested repetition structures Make sure the outer loop completely contains the inner loop Introduction to Programming with C++, Fourth Edition


Download ppt "Chapter 8: More on the Repetition Structure"

Similar presentations


Ads by Google