Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.

Slides:



Advertisements
Similar presentations
Chapter 6: The Repetition Structure
Advertisements

Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Chapter 04 (Part III) Control Statements: Part I.
CS0004: Introduction to Programming Repetition – Do Loops.
Objectives In this chapter, you will learn about:
Repeating Actions While and For Loops
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 5 Looping.
An Introduction to Programming with C++ Fifth Edition
An Introduction to Programming with C++ Fifth Edition Chapter 8 More on the Repetition Structure.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Chapter 5: Repetition Statements. In this chapter, you will learn about: Basic loop structures while loops Interactive while loops for loops Loop programming.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Programming Logic and Design Fifth Edition, Comprehensive
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
Chapter 6: The Repetition Structure
Tutorial 6 The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
CHAPTER 3 CONTROL STRUCTURES ( REPETITION ) I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
Computer Programming TCP1224 Chapter 8 More On Repetition Structure.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Chapter 13 Do It, Then Ask Permission (Posttest Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 14 Do It, Then Ask Permission.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 5 Looping.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
CHAPTER 4 REPETITION STRUCTURES 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
Chapter 8: More on the Repetition Structure
Exam 2 Review.
REPETITION CONTROL STRUCTURE
Programming Logic and Design Fourth Edition, Comprehensive
JavaScript: Control Statements I
Chapter 5: Loops and Files.
Chapter 5: Repetition Structures
Ch 7: JavaScript Control Statements I.
Chapter 4 Repetition Structures
Chapter 4 Repetition Structures
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
CIS 16 Application Development Programming with Visual Basic
Chapter 8: More on the Repetition Structure
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Presentation transcript:

Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition

Introduction to Programming with C++, Fourth Edition 2 Objectives 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

Introduction to Programming with C++, Fourth Edition 3 Using the Repetition Structure Repetition structure or loop - allows repeated processing of one or more program instructions until some condition is met Repetition structure can be either a pretest loop or a posttest loop –Pretest loop: evaluation occurs before loop instructions are processed –Posttest loop: evaluation occurs after loop instructions are processed

Introduction to Programming with C++, Fourth Edition 4 Pretest Loops

Introduction to Programming with C++, Fourth Edition 5 Pretest Loops (continued)

Introduction to Programming with C++, Fourth Edition 6 Pretest Loops (continued) Every loop has: –a loop condition –a loop body Loop body: –instructions within a loop Loop condition: –appears at the beginning of a pretest loop –determines the number of times instructions within the loop are processed

Introduction to Programming with C++, Fourth Edition 7 Sentinel value – special value to end the loop Priming read: –Appears above the loop –Used to prepare or set up the loop Pretest Loops (continued)

Introduction to Programming with C++, Fourth Edition 8 Components of a Loop

Introduction to Programming with C++, Fourth Edition 9 O’Donnell Incorporated Algorithm Shown in Flowchart Form

Introduction to Programming with C++, Fourth Edition 10 Using the while Statement to Code the Pretest Loop While statement: 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 Endless or infinite loop – one that processes its instructions indefinitely

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

Introduction to Programming with C++, Fourth Edition 12 Using Counters and Accumulators Counter - a numeric variable used for counting Accumulator - a numeric variable used for accumulating a value Initializing - assigning a beginning value to the counter or accumulator Updating or incrementing - adding a number to the value stored in the counter or the accumulator

Introduction to Programming with C++, Fourth Edition 13 Counter-Controlled Pretest Loops

Introduction to Programming with C++, Fourth Edition 14 Using the for Statement to Code a Pretest Loop Most common use for the for statement: –Code pretest loops whose processing is controlled by a counter For statement: –Begins with the for clause –Followed by the body of the loop If the loop body contains more than one statement: –Statements must be entered as a statement block i.e., enclosed in braces ({})

Introduction to Programming with C++, Fourth Edition 15 Syntax of the C++ for statement

Introduction to Programming with C++, Fourth Edition 16 for Statement Displays the Numbers 1 Through 3

Introduction to Programming with C++, Fourth Edition 17 for Statement Calculates and Displays a Commission

Introduction to Programming with C++, Fourth Edition 18 for Statement Calculates and Displays a Bonus

Introduction to Programming with C++, Fourth Edition 19 Summary Repetition structure or loop - allows repeated processing of one or more program instructions until some condition is met –Repetition structures contain a condition and a loop body