Repetition - Counting and Accumulating

Slides:



Advertisements
Similar presentations
Chapter 6 - VB 2005 by Schneider1 Do Loop Syntax Do While condition statement(s) Loop Condition is tested, If it is True, the loop is run. If it is False,
Advertisements

Looping Structures: Do Loops
Quiz 2. Quiz 2 What is output (5 Marks) [8 min] X = 987 Y = X Z = 0 Do Do While (Y > 0) Z = Z + Y Mod 10 Y = Y \ 10 Loop Y = Z Z = 0 Loop Until (Y < 10)
Chapter 6: The Repetition Structure
Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Practical Programming COMP153-08S Lecture: Repetition Continued.
CS0004: Introduction to Programming Repetition – Do Loops.
VB PROJECT “PROJECT SAMPLES”. For Next Loops Design a VB program that displays in a picture box the first N multiples of an input integer Input 3 exam.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Repeating Actions While and For Loops
1 Loops zDo While Loop: yRepeats a block of code WHILE a condition remains TRUE Do While condition Code to execute Loop.
An Introduction to Programming with C++ Fifth Edition
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
5.05 Apply Looping Structures
Muffin Shop - if, calculations etc. (muffins, muffins2) Please use speaker notes for additional information!
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Break Processing Please use speaker notes for additional information!
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
Chapter 12: How Long Can This Go On?
Repetition Chapter 7. Overview u For Loop u Do Loop  Do While Loop  Do Until Loop  Do Loop While  Do Loop Until u Nested Loops.
Component 4/Unit 5-4. Iteration (Repetition, Looping, Do loops) Loops are used to execute statements repetitively Loops require a conditional test that.
Do Loop with Interest Please see speaker notes for additional information!
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
1 Flow Control II Code: Select-Case and For-Next Controls: Frames and OptionButtons.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 8: Chapter 5: Slide 1 Unit 8 List Boxes and the Do While Looping Structure.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
Chapter 6: The Repetition Structure
Tutorial 6 The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
Chapter 4 Looping Statements Adapted From: Starting Out with Visual Basic 2008 (Pearson)
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Count and add list of numbers From user input and from file.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Pay Example (PFirst98) Please use speaker notes for additional information!
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:
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Controlling Program Flow with Looping Structures
Repetition Yonglei Tao. Display Numbers num = 1 lblDisplay.Text = num & ControlChars.NewLine num = 2 * 2 lblDisplay.Text = lblDisplay.Text & num & ControlChars.NewLine.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 Controlling Program Flow with Looping Structures.
Chapter 5 - VB 2008 by Schneider1 Chapter 5 – Repetition 5.1 Do Loops 5.2 Processing Lists of Data with Do Loops 5.3 For...Next Loops.
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:
CHAPTER #7 Problem Solving with Loop. Overview Loop logical structure Incrementing Accumulating WHILE/WHILE-END FOR Nested loop Pointer Algorithmic instruction.
Visual Basic - Break Processing
Processing multiple files
Bands Submit Private Sub btnSubmit_Click() Dim band As String
Clearly Visual Basic: Programming with Visual Basic nd Edition
Repetition – For and Do While
Selection Structures (Part 1)
Lists, Loops, Validation, and More
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Repeating Program Instructions
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Microsoft Visual Basic 2005: Reloaded Second Edition
Conditional Construct
Movie Rater.
Active-X Calendar Control
Visual Basic Programming
Topics Introduction to Repetition Structures
Introduction to Computer Programming IT-104
Repetition – The For Loop
Presentation transcript:

Repetition - Counting and Accumulating Yonglei Tao

Flow Chart – Pretest Loop

Flow Chart – Posttest Loop

Counting and Accumulating Write a program to process input, the number of input values are unknown Sample input 27.50 55.00 38.74 88.26 <empty string> 27.50 63.98 55.00 96.11 38.74 88.26 <empty string> <empty string>

Loop Design Get a value If it is not the empty string Process the value Get next value … If it is the empty string Done Get a value Do While it’s not an empty string Process the value Get next value Loop

Program Version One Private Sub btnCalculate_Click ( … ) Dim sales As String Dim numSales As Integer sales = InputBox (“Enter a sales amount. Click Cancel to end.“, “Sales Entry”) Do While sales <> String.Empty ‘ process the value Loop ‘ display the average End Sub

Program Version Two Private Sub btnCalculate_Click ( … ) Dim sales As String Dim numSales As Integer Dim totalSales, avgSales As Currency sales = InputBox (“Enter a sales amount. Click Cancel to end.“, “Sales Entry”) Do While sales <> String.Empty ‘ process the value numSales = numSales + 1 totalSales = totalSales + Val (sales) Loop ‘ display the average End Sub

Private Sub btnCalculate_Click ( … ) Dim sales As String Dim numSales As Integer Dim totalSales, avgSales As Currency sales = InputBox (“Enter a sales amount. Click Cancel to end.“, “Sales Entry”) Do While sales <> String.Empty numSales = numSales + 1 totalSales = totalSales + Val (sales) Loop If ( numSales > 0 ) Then avgSales = totalSales / numSales lblAerage.Text = Format ( avgSales. “Currency”) else lblAerage.Text = “No Sales” end If End Sub