CH07 - An Introduction to Programming with C+, Fifth...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
An Introduction to Programming with C++, Fifth Edition 7 - 1 Chapter 7 The Repetition Structure At a Glance Instructor’s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Topics Classroom Activities/Additional Projects Key Terms
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
An Introduction to Programming with C++, Fifth Edition 7 - 2 Lecture Notes Chapter Overview This chapter covers the repetition structure. Included is the proper design of a repetition structure using flowcharts and/or pseudocode, as well as the actual implementation of the repetition structure in C++ using the while statement and for statement. Integrated with the repetition structure is the concept of initializing and updating counters and accumulators. Chapter Objectives After completing the chapter, the student will be able to: Include a repetition structure in pseudocode and in a flowchart Code a pretest loop using the C++ while statement Initialize and update counters and accumulators Code a pretest loop using the C++ for statement Instructor Notes Using the Repetition Structure The repetition structure, also called a loop, is one of the three basic control structures used in programming. The other two control structures are sequence and the selection structure, which have been covered in previous chapters. The repetition structure is used when you would like the program to repeatedly process one or more program instructions until some condition is met, at which time the repetition structure ends. Pretest Loops A repetition structure can either be a pretest loop or posttest loop. In a pretest loop, the loop condition is evaluated before the instructions within the loop are processed; while in a posttest loop, the evaluation occurs after the instructions within the loop are processed. Of the two types of loops, the pretest loop is the most commonly used. You will cover the pretest loop in this chapter. The posttest loop will be covered in the next chapter. With very rare exceptions, every loop has a loop condition and a loop body. The loop condition appears at the beginning of a pretest loop and determines the number of times the instructions within the loop, referred to as the loop body, will be processed. Similar to a selection structure condition, a loop condition must result in either a true or false value (a boolean value).
Background image of page 2
An Introduction to Programming with C++, Fifth Edition 7 - 3 When the loop condition evaluates to true, the one or more instructions listed in the loop body are processed. If the loop condition evaluates to false, the instructions listed in the loop body are skipped over and control is passed to the next statement after the loop. Because the loop condition in a pretest loop is evaluated before any of the instructions within the
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2010 for the course CS 343 taught by Professor Katzman during the Spring '09 term at ITT Tech Tucson.

Page1 / 8

CH07 - An Introduction to Programming with C+, Fifth...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online