Fac of Ene & Surveying U.S.Q.1 E0001 Computers in Engineering DO.... LOOP.

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

How SAS implements structured programming constructs
Lesson 5 - Decision Structure By: Dan Lunney
UNIT 3 PROBLEM SOLVING WITH LOOP AND CASE LOGIC STRUCTURE
CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Chapter 2: Algorithm Discovery and Design
Chapter 61 Post Test Loop Do statement(s) Loop Until condition Loop is executed once and then the condition is tested. If it is False, the loop is run.
Program Design and Development
Chapter 5: Control Structures II (Repetition)
Chapter 5: Loops and Files.
Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
16/27/ :53 PM6/27/ :53 PM6/27/ :53 PMLogic Control Structures Arithmetic Expressions Used to do arithmetic. Operations consist of +,
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Programming Logic and Design Fifth Edition, Comprehensive
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
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.
Control Structures II (Repetition). Objectives In this chapter you will: Learn about repetition (looping) control structures Explore how to construct.
Chapter 6 Looping CS185/09 - Introduction to Programming Caldwell College.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
259 Lecture 11 Spring 2013 Advanced Excel Topics – Loops.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CPS120 Introduction to Computer Science Iteration (Looping)
Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Loops and Files. 5.1 The Increment and Decrement Operators.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Chapter 3 Decisions Three control structures Algorithms Pseudocode Flowcharts If…then …else Nested if statements Code blocks { } multi statement blocks.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 14 Do It, Then Ask Permission.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Programming Logic and Design Fifth Edition, Comprehensive
Java Programming: From Problem Analysis to Program Design, 4e Chapter 5 Control Structures II: Repetition.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 5 Control Structures II: Repetition.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
LOOPS CHAPTER Topics  Four Types of Loops –while –do…while –for –foreach  Jump Statements in Loops –break –continue 2.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Lecture 7 – Repetition (Loop) FTMK, UTeM – Sem /2014.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 6.
Chapter 6 Looping. 2 l A loop is a repetition control structure. l it causes a single statement or block to be executed repeatedly What is a loop?
Follow up from lab See Magic8Ball.java Issues that you ran into.
Discussion 4 eecs 183 Hannah Westra.
REPETITION CONTROL STRUCTURE
Advanced Excel Topics – Loops
CS1371 Introduction to Computing for Engineers
Numbering System TODAY AND TOMORROW 11th Edition
Chapter 5: Loops and Files.
Computer Science Faculty
A First Book of ANSI C Fourth Edition
Understanding the Three Basic Structures
Iteration: Beyond the Basic PERFORM
Chapter 2.1 Repetition.
Repetition Control Structure
Chapter 8: More on the Repetition Structure
Three Special Structures – Case, Do While, and Do Until
ICT Programming Lesson 3:
A LESSON IN LOOPING What is a loop?
CHAPTER 21 LOOPS 1.
Chapter 4: Repetition Structures: Looping
ECE 103 Engineering Programming Chapter 18 Iteration
Programming Right from the Start with Visual Basic .NET 1/e
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Presentation transcript:

Fac of Ene & Surveying U.S.Q.1 E0001 Computers in Engineering DO.... LOOP

Fac of Ene & Surveying U.S.Q.2 Readings l Schneider Chapter 6 sections 6.1 and problems as required l Schneider p 84 on TUTORIALS l WILL CONTINUE BUT NOT COMPULSORY

Fac of Ene & Surveying U.S.Q.3 This Lecture: l two types POST TEST DO.. LOOPS l INKEY$ statement

Fac of Ene & Surveying U.S.Q.4 DO LOOP l loops repeat a set of statements - used when an UNKNOWN number if iterations is required l DO indicates the top of the loop LOOP indicates the end of the loop l DO without a LOOP and visa versa will give a run time error. Same rules for NESTED loops apply l four ways to write a DO LOOP –pre & post test; WHILE & UNTIL

Fac of Ene & Surveying U.S.Q.5 conditions l conditions use RELATIONAL and LOGIC operators l evaluated to TRUE or FALSE l if conditions are not met, the control passes to statement immediately after the LOOP

Fac of Ene & Surveying U.S.Q.6 Program l write a program to read the product code, number on hand and number on order for an unknown number of products

Fac of Ene & Surveying U.S.Q.7 pseudocode data to read ? no read code, # on hand, # on order print ‘end’ end

Fac of Ene & Surveying U.S.Q.8 code DO WHILE code$ <> “eof” READ code$, onhand, onorder PRINT code$, on hand, onorder LOOP PRINT “end of report” DATA glue,5,7,tape,1,20,book1,2,30, paper, 4,3,eof,0,0

Fac of Ene & Surveying U.S.Q.9 Pre - test Loop l DO WHILE condition statement (s) LOOP l DO UNTIL condition statement(s) LOOP l condition tested before statements are executed l statements executed if condition true

Fac of Ene & Surveying U.S.Q.10 Post - test Loops l DO statement(s) LOOP WHILE condition l DO statement(s) LOOP UNTIL condition l in post-test loops statements are executed at least once

Fac of Ene & Surveying U.S.Q.11 Post-test WHILE loop flowchart execute statements in loop condition True False DO statements LOOP WHILE condition

Fac of Ene & Surveying U.S.Q.12 Post-test UNTIL loop flowchart execute statements in loop condition True False DO statements LOOP UNTIL condition

Fac of Ene & Surveying U.S.Q.13 INKEY$ l Reads a character from the keyboard. l INKEY$ returns a null string if there is no character to return. l Example: PRINT "Press Esc to exit..." DO LOOP UNTIL INKEY$ = CHR$(27) '27 is the ASCII code for Esc.

Fac of Ene & Surveying U.S.Q.14 beware!! DO INPUT choice$ SELECT CASE choice$ CASE circle:..... CASE square:... CASE ELSE :..... END SELECT LOOP INKEY$<>““‘null string INKEY$ executes quickly! Unless you are pressing a key at the exact instant the statement executes it will return a null string and hence loop