CE 311 K - Introduction to Computer Methods Daene C. McKinney

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

CS107: Introduction to Computer Science Lecture 2 Jan 29th.
CS0004: Introduction to Programming Repetition – Do Loops.
CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Repeating Actions While and For Loops
Chapter 5: Control Structures II (Repetition)
Chapter 5: Control Structures II (Repetition)
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Chapter 6 - Visual Basic Schneider
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Chapter 14: Generating Data with Do Loops OBJECTIVES Understand iterative DO loops. Construct a DO loop to perform repetitive calculations Use DO loops.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Chapter 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Processing Lists of Data with Do Loops (Examples)
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
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.
Chapter 71 Repetition - Do Loops n A Loops, is used to repeat a sequence of statements a number of time n There are two loops commands in Visual Basic.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 5: Control Structures II (Repetition)
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
Control Structures II (Repetition). Objectives In this chapter you will: Learn about repetition (looping) control structures Explore how to construct.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Visual Basic Programming
Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 6: Sections 6.2, 6.3 Roxana Gheorghiu Friday, April 1, 2011.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
Chapter 6 - VB 2008 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study: Analyze a Loan.
CHAPTER 6: REPETITION AND LOOP STATEMENTS Learning outcomes  Define the concept of repetition structure.  Specify.
Chapter 6: Loops.
REPETITION CONTROL STRUCTURE
CHAPTER 6: REPETITION AND LOOP STATEMENTS
Topics Introduction to Repetition Structures
Programming Logic and Design Fourth Edition, Comprehensive
Control Structures II (Repetition)
Chapter 5: Repetition Structures
CiS 260: App Dev I Chapter 4: Control Structures II.
Topics Introduction to Repetition Structures
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
CSC115 Introduction to Computer Programming
Repetition and Loop Statements
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
Repetition Control Structure
Chapter 6: Repetition Statements
Let’s all Repeat Together
ICT Programming Lesson 3:
Chapter 6 - VB.Net by Schneider
Topics Introduction to Repetition Structures
Chapter 4: Repetition Structures: Looping
CS2011 Introduction to Programming I Loop Statements (I)
Presentation transcript:

CE 311 K - Introduction to Computer Methods Daene C. McKinney Repetition CE 311 K - Introduction to Computer Methods Daene C. McKinney

Introduction Do – While Loops Do – Until Loops Peek For – Next Loops

Repetition - Loops Control structures used to repeat statements until a condition is met Do loop Indeterminate looping structure Condition stops the loop For – Next loop Determinate looping structure Number of cycles stops the loop

Do – While Loops Do While condition Statement(s) … Loop Loop ? no yes Beginning of loop End of loop Do While condition Statement(s) … Loop

Do – While Loops

Do - Until Loops Do Statements… Loop Until condition Loop ? no yes Beginning of loop End of loop Do Statements… Loop Until condition ?

Do - Until Loops

Notes on Loops Avoid “Infinite” loops Any “Do-While” statement can be converted to an “Do-Until” statement, and vice-versa “Do-While” tests at the top of the loop “Do-Until” tests at the bottom of the loop

Processing Data With Loops Data in files Display Select/Search Calculation/Transform Detect the end of a file (EOF) Peek: determine when end of file is reached Counters: Calculate # of elements in a list Accumulators: Sum numerical values in lists Flags: Test for certain conditions

Peek Read data from a file using a Do Loop How do we detect the End Of File (EOF)? Value of sr.Peek = 1st character of current line in file If EOF has been reached sr.Peek = -1

Central Asia Toktogul Dam 140 m 19.5 km3

Naryn River Annual Flows 92 annual flows isn’t such a hard problem, but these are derived from 35,580 daily flows – too much for a spreadsheet.

Peeking Into a Data File Do While sr.Peek <> -1 More data in the file? no Do While sr.Peek <> -1 flow = sr.ReadLine sum = sum + flow count = count + 1 Loop yes Get more data from file Accumulator Counter Process the data Execute remaining statements

Using Peek

For – Next Loops For i = m To n statement(s) Next Loop yes Beginning of loop End of loop Execute statements i > n ? yes no i = m I = i + 1 For i = m To n statement(s) Next i – control variable m – initial value of i n – terminating value of i next – increment i by 1 statements – get executed

Example Suppose the population of a city is 200,000 in 2009 and is expected to grow at a rate of 3% per year. Display the population every year up to 2015.

Example Step s

Example - Factorial

Nested For – Next Loops

Example Standard Deviation

Summary Do – While Loops Do – Until Loops Peek For – Next Loops