Pascal Programming Pascal Loops and Debugging. Pascal Programming Pascal Loops In our first brush with the while do loops, simple comparisons were used.

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.
CS0004: Introduction to Programming Repetition – Do Loops.
Objectives In this chapter, you will learn about:
Computer Science 1620 Loops.
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Chapter 5: Loops and Files.
Loops Repeat after me …. Loops A loop is a control structure in which a statement or set of statements execute repeatedly How many times the statements.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
5.05 Apply Looping Structures
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
Chapter 5: Control Structures II (Repetition)
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
Programming Logic and Design Fifth Edition, Comprehensive
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part D (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
Chapter 6 Looping CS185/09 - Introduction to Programming Caldwell College.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Control Structures Repetition or Iteration or Looping Part II.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 5 Looping.
Design of Bio-Medical Virtual Instrumentation Tutorial 2.
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
Pascal Programming Iteration (looping) Carl Smith National Certificate Unit 4.
Loops and Files. 5.1 The Increment and Decrement Operators.
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.
Chapter 4 Introduction to Control Statements
Controlling Program Flow with Looping Structures
Iteration & Loop Statements 1 Iteration or Loop Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
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.
Flow of Control: Loops Module 4. Objectives Design a loop Use while, do, and for in a program Use the for-each with enumerations Use assertion checks.
COMP Loop Statements Yi Hong May 21, 2015.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Catie Welsh February 9,  Friday - No Lab! ◦ Bring questions on Project 2  Lab 3 due on Friday 2.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
1 Looping Chapter 6 2 Getting Looped in C++ Using flags to control a while statement Trapping for valid input Ending a loop with End Of File condition.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Control Structures Repetition or Iteration or Looping Part II.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
ECE Application Programming
REPETITION CONTROL STRUCTURE
ECE Application Programming
Chapter 6 Looping.
Introduction To Repetition The for loop
Lesson 05: Iterations Class Chat: Attendance: Participation
Programming Logic and Design Fourth Edition, Comprehensive
Loop Structures.
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Control Structures - Repetition
Looping and Repetition
MSIS 655 Advanced Business Applications Programming
Chapter 6: Repetition Statements
Loop Strategies Repetition Playbook.
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Looping and Repetition
Presentation transcript:

Pascal Programming Pascal Loops and Debugging

Pascal Programming Pascal Loops In our first brush with the while do loops, simple comparisons were used. Now, we add the Boolean expression. As long as the expression evaluates as true, the loop continues. False stops the looping.

Pascal Programming The repeat statement, another method of looping. Syntax... –repeat Statement or statements; –until Boolean-expression –end

Pascal Programming The body of a repeat may contain multiple statements... The body of the while statement contains one statement. The difference holds limited significance because the while statement may be compound.

Pascal Programming The for loop... Syntax... –For Control_variable := Initial_expression to Final_expression do –Body The value increments by one each time through the loop. The body of the for loop can not change the loop-control variable. The loop-control variable is intended for exclusive use of the loop. (a local variable)

Pascal Programming The second version of the for loop decrements... In the statement downto replaces to Downto is a reserved word. Each time through the loop it decreases by one. Note: Pascal only increments by one or decrements by one. You must design around this limitation. e g. You want 0, 2, 4, 6, 8, –For N := 0 to 5 do –Write (2*N)

Pascal Programming When designing a Pascal loop, design… The Body The initializing statements The conditions for exiting the loop. We have talked about the first two no let’s look at terminating the loop.

Pascal Programming Terminating a loop... –Terminating input List is headed by size (list size is known) Ask before iterating (ask the user) List ended by sentinal value. Input runs out.

Pascal Programming Terminating the loop... –Count the controlled loops. –Ask before iterating. –Exit on sentinel value. –Input runs out. –Exit on a flag condition. A flag is a variable that changes value to indicate that an event has occurred. The end of line (eoln) and end of file (eof) are examples. (Eoln does not work well with numeric data. It prefers char type.)

Pascal Programming What loop should I use? Numeric data, fixed iterations, equal changes each time...use for Generally, the for loop will be best for numeric data. If the loop may not be used at least once, use while. It also works when no data may be entered from a list. If you insist that the loop be used at least once, use repeat.

Pascal Programming Assertions Comments about pre- and post- conditions are called assertions. An invariant assertion is true before the loop runs and true after. The variable changes with each iteration but holds true with each iteration. Thus it is invariant. continue...

Pascal Programming Assertions cont... A variant assertion changes after each iteration. Two conditions... –The value must decrease by a fixed amount (or more) each iteration. –When the variant equals or falls below the threshold, the loop must stop. –The threshold is the point to be reached or passed.

Pascal Programming Debugging Loops For repeat or while loops...check the Boolean expression. Is something reversed? Be sure that the error is in the loop. Trace the data through the loop. Check intervals in long loops.