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

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 5: Looping by Tony.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Chapter 5: Control Structures II (Repetition)
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Nested Loops. Nesting Control Structures One if statement inside another one An if statement inside a loop A loop inside an if statement Control structures.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
1 What is a loop? A loop is a repetition control structure that causes a single statement or block to be executed repeatedly Loops.
While Loops CMSC 201. Overview Today we will learn about: Looping Structures While loops.
CPS120 Introduction to Computer Science Iteration (Looping)
Programming Logic and Design Fifth Edition, Comprehensive
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
The world of Constructs Control Structures. The three Structures Sequence Selection Loop Entry Exit.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Overview Go over parts of quiz? Another iteration structure for loop.
CPS120 Introduction to Computer Science Iteration (Looping)
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Manipulating Data Concepts Covered: Literal values, variables and Types Variables.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Loops and Files. 5.1 The Increment and Decrement Operators.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
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.
COP 2510 Programming ConceptsAlessio Gaspar BSAS Industrial Operations 1 Conditional Statements Concepts Covered: Conditional Statements Serially Arranged.
Iteration & Loop Statements 1 Iteration or Loop Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Introduction to Computing Concepts Note Set 14. What if… You had to print “I love Java” to the screen 125 times. How? 125 lines of ▫ System.out.println(“I.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
1 Fall 2009ACS-1903 Ch 4 Loops and Files while loop do-while loop for loop Other topics later on …
Java Programming: From Problem Analysis to Program Design, 4e Chapter 5 Control Structures II: Repetition.
1 Week 9 Loops. 2 Repetition: Loops l Structure: »Usually some initialization code »body of loop »loop termination condition l Several logical organizations.
While ( number
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Exam 2 Review.
Chapter 4 Repetition Statements (loops)
Department of Computer Science
Chapter 3: Decisions and Loops
Programming Logic and Design Fourth Edition, Comprehensive
Chapter 5: Repetition Structures
CiS 260: App Dev I Chapter 4: Control Structures II.
( Iteration / Repetition / Looping )
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Iteration: Beyond the Basic PERFORM
Chapter 8: More on the Repetition Structure
3.5- The while Statement The while statement has the following syntax:
Program Flow.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
PROGRAM FLOWCHART Iteration Statements.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Chapter 2 Sets Active Learning Lecture Slides
Database Programming Using Oracle 11g
Presentation transcript:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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