Processing Lists of Data with Do Loops (Examples)

Slides:



Advertisements
Similar presentations
Introduction to File I/O How to read & write data to a disk file...
Advertisements

Branching Constructs Review l what are branching constructs? what type of branching constructs have we studied? l what is nested if? l what is multiway.
1 Prototyping for HCI Spring 2004 (Week 9) Jorge A. Toro.
Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
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.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
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.
Control Structures Control structures control the flow of program execution. 3 types of control structures: sequence, selection.
Chapter 61 Flags A flag is a variable that keeps track of whether a certain situation has occurred. The data type most suited to flags is Boolean.
An Object-Oriented Approach to Programming Logic and Design Chapter 7 Arrays.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Using Arrays and File Handling
STRINGS CMSC 201 – Lab 3. Overview Objectives for today's lab:  Obtain experience using strings in Python, including looping over characters in strings.
For Loops (ProjFor1, ProjFor2, ProjFor3, ProjFor4, textbox, textbox1) Please use speaker notes for additional information!
Array Processing.
+ ARRAYS - SEARCHING - SORTING Dr. Soha S. Zaghloul updated by Rasha M. AL_Eidan 2015.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
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.
R EPETITION 1 Chapter 6. C HAPTER 6 – R EPETITION 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study: Analyze.
 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.
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.
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
259 Lecture 11 Spring 2013 Advanced Excel Topics – Loops.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Chapter 6: Sections 6.2, 6.3 Roxana Gheorghiu Friday, April 1, 2011.
Counting Loops.
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:
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
1 Chapter 3: Loops and Logic. 2 Control Statements If statement Example NumberCheck.java Relational operators (, >=, ==, !=) Using code blocks with If.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Chapter 61 Example : For … To… Step For index = 0 To n Step s lstValues.Items.Add(index) Next Control variable Start value Stop value Amount to add to.
CS 4 Intro to Programming in Visual Basic Files and Loops (2) Patchrawat Uthaisombut University of Pittsburgh 1.
Controlling Program Flow with Looping Structures
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 13 Conditional.
Iteration & Loop Statements 1 Iteration or Loop Statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
A club in Leicester holds exclusive after party sessions for members only. In order to get into one of the after parties you need to be “on the list”.
CISC105 – General Computer Science Class 4 – 06/14/2006.
Lab 4 Instructions If you have a text book, you can go to drill at pp. 126 for steps 1-6 at the end of chapter 4, Or you can read following slides of the.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
PROGRAMMING INFORMATION. PROCEDURES IN PYTHON Procedures can make code shorter, simpler, and easier to write. If you wanted, for example, to use a certain.
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 5: Control Structures II (Repetition)
An Introduction to Programming with C++ Sixth Edition
Advanced Excel Topics – Loops
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Control Structures II (Repetition)
CiS 260: App Dev I Chapter 4: Control Structures II.
CE 311 K - Introduction to Computer Methods Daene C. McKinney
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
A First Book of ANSI C Fourth Edition
Iteration: Beyond the Basic PERFORM
Chapter 6: Repetition Statements
Chapter 6 - VB.Net by Schneider
Common pattern/tool: Accumulator loops
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 13 Control Structures
Presentation transcript:

Processing Lists of Data with Do Loops (Examples) 1. Phone Book Enquiry – (Lab sheet 6.3) (Using Peek Method) 2. Find the sum of a series of number. – (Using Counters and Accumulators) 3. Password Checking –(Using Flags) 4. Nested Loops – (Lab sheet 6.6) Chapter 6

Lab sheet 6.3: Phone Number Enquiry txtName btnDisplay txtNumber First, build the Form with the above layout Chapter 6

What is sr.Peek ? Sr.peek is the result of reading the text file. It will return the next character, if not available, it will return -1. Chapter 6

Lab sheet 6.3 : Phone Book Enquiry (Using Do-While Loop) Do While (name <> txtName.Text) _ And (sr.Peek <> -1) name = sr.ReadLine phoneNum = sr.ReadLine Loop As long as the name being searched for has not been found AND the end of the file has not been reached, the loop will continue This make sure there is some text remains in the text file for the program to read. Chapter 6

Example : Phone Book Enquiry (Using Do … Loop Until) name = sr.ReadLine phoneNum = sr.ReadLine Loop Until (name <> txtName.Text) _ or (sr.Peek <> -1)) Until the name being searched matches the data OR the end of the file has been reached, the loop will Stop Chapter 6

Counters and Accumulators A counter is a numeric variable that keeps track of the number of items that have been processed. An accumulator is a numeric variable that totals numbers. In the following example, variable CurrNum is a counter while Ans is a accumulator. Chapter 6

First, build the Form with the above layout Lab sheet 6.4: Find the sum of a series of number (Using Do-While Loop) txtstart txtend btnCalculate txtAns First, build the Form with the above layout Chapter 6

Sum of a series of number - Partial Code Dim EndNo As Double Dim Ans As Double Dim CurrNum As Double CurrNum = txtStart.Text EndNo = txtEnd.Text Ans = 0 Do While CurrNum <= EndNo Ans = Ans + CurrNum CurrNum = CurrNum + 1 Loop txtAns.Text = Ans CurrNum is a counter, it increases by 1 each time through the loop Ans is an accumulator. It is used to total up the values. Chapter 6