1 / 10

Chapter 8: More on the Repetition Structure

Chapter 8: More on the Repetition Structure. Introduction to Programming with C++ Fourth Edition . 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. Posttest Loops.

jamil
Download Presentation

Chapter 8: More on the Repetition Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

More Related