Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.

Slides:



Advertisements
Similar presentations
1.
Advertisements

Chapter 6: The Repetition Structure
Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
1.
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Chapter 11: Classes and Objects
Programming with Microsoft Visual Basic th Edition
1.
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
5.05 Apply Looping Structures
Chapter 5 new The Do…Loop Statement
1.
CHAPTER SIX Loop Structures.
CHAPTER 6 Loop Structures.
Programming with Microsoft Visual Basic 2012 Chapter 7: Sub and Function Procedures.
Chapter Four The Selection Structure
Chapter 4: The Selection Structure
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
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 with Microsoft Visual Basic 2008 Fourth Edition
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
Programming Logic and Design Fifth Edition, Comprehensive
Creating Classes and Objects Chapter Microsoft Visual Basic.NET: Reloaded 1.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
© 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.
Chapter 6: The Repetition Structure
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
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.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Programming with Microsoft Visual Basic th Edition
Computer Programming TCP1224 Chapter 8 More On Repetition Structure.
1.
Chapter Four The Selection Structure Programming with Microsoft Visual Basic th Edition.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
7-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 13 How Long Can This Go On?
Chapter 13 Do It, Then Ask Permission (Posttest Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Controlling Program Flow with Looping Structures
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Looping Structures. A B dialog box that pops up and prompts the user for input Text area that pops up and prompts the user for to wait while it gets.
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 9: Chapter 5: Slide 1 Unit 9 Do Until and For… Next Loops Chapter 5 Lists,
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 Controlling Program Flow with Looping Structures.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
Microsoft Visual Basic 2008: Reloaded Third Edition
Clearly Visual Basic: Programming with Visual Basic nd Edition
Lists, Loops, Validation, and More
Repeating Program Instructions
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Microsoft Visual Basic 2005: Reloaded Second Edition
CIS 16 Application Development Programming with Visual Basic
Presentation transcript:

Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1

2 Objectives Include the repetition structure in pseudocode and in a flowchart Write a For…Next statement Calculate a periodic payment using the Pmt function Write a Do…Loop statement Initialize and update counters and accumulators Display a dialog box using the InputBox function

3 Microsoft Visual Basic.NET: Reloaded The Repetition Structure Repetition Structure (also known as a loop) Repeatedly processes a set of instructions until a condition is met Pretest loop: Evaluation occurs before instructions within loop PostTest loop: Evaluation occurs after the instructions within loop are processed Instructions will always be processed at least once

4 Microsoft Visual Basic.NET: Reloaded The For…Next Statement Use to code a loop to process instructions a precise number of times For…Next is a pretest loop StartValue (starting value of loop counter) EndValue (ending value of loop counter) Stepvalue (amount of change of loop counter) Default stepvalue is a positive 1 Can be negative Designate with Step keyword Example Step -2 Subtracts 2 from the loop counter

5 Microsoft Visual Basic.NET: Reloaded HOW TO…

6 Microsoft Visual Basic.NET: Reloaded The For…Next Statement ( continued )

7 Microsoft Visual Basic.NET: Reloaded The For…Next Statement ( continued )

8 Microsoft Visual Basic.NET: Reloaded The Pmt Function Use to calculate a periodic payment on a loan or investment Contains 5 arguments Rate, Nper, PV are required FV, Due are optional Negation operator reverses the sign of a number -Pmt(.05,3,9000)

9 Microsoft Visual Basic.NET: Reloaded HOW TO…

10 Microsoft Visual Basic.NET: Reloaded The Payment Calculator Application

11 Microsoft Visual Basic.NET: Reloaded The Payment Calculator Application ( continued )

12 Microsoft Visual Basic.NET: Reloaded The Do…Loop Statement Can be used to code both pretest and posttest loops Do While or Do Until is a pretest loop Pretest loops should have a “priming read” Data input entry placed above loop Loop While or Loop Until is a posttest loop [While|Until] portion can only contain one of the keywords (While or Until) While processes instructions as long as the condition evaluates true Until processes instructions until the condition becomes true

13 Microsoft Visual Basic.NET: Reloaded HOW TO…

14 Microsoft Visual Basic.NET: Reloaded The Do…Loop Statement ( continued )

15 Microsoft Visual Basic.NET: Reloaded The Do…Loop Statement ( continued )

16 Microsoft Visual Basic.NET: Reloaded The Do…Loop Statement ( continued )

17 Microsoft Visual Basic.NET: Reloaded The Do…Loop Statement ( continued )

18 Microsoft Visual Basic.NET: Reloaded The Do…Loop Statement ( continued )

19 Microsoft Visual Basic.NET: Reloaded Using Counters and Accumulators Counter – numeric variable used for counting something  number of employees paid in a week Accumulator – numeric variable used for calculating running totals  total dollar amount of weeks payroll Initializing – assigning a beginning value to a variable Updating (incrementing) – adding a number to the value stored in the counter or accumulator

20 Microsoft Visual Basic.NET: Reloaded The Sales Express Application Application for sales manager to display average amount the company sold during the prior year. Sales manager will enter each salesperson’s sales Application will use a counter to keep track of number of sales amounts and an accumulator to total those amounts

21 Microsoft Visual Basic.NET: Reloaded The Sales Express Application ( continued )

22 Microsoft Visual Basic.NET: Reloaded The InputBox Function Displays a dialog box that prompts the user in input information Contains a prompt, one or more buttons, and an input area for data entry Prompt - message you want displayed Title displays caption of input box defaultResponse - initial text displayed in the input area Ok button returns value in input area, Cancel and Close buttons return empty string

23 Microsoft Visual Basic.NET: Reloaded The InputBox Function ( continued )

24 Microsoft Visual Basic.NET: Reloaded The InputBox Function ( continued )

25 Microsoft Visual Basic.NET: Reloaded Code for the Sales Express Application

26 Microsoft Visual Basic.NET: Reloaded Programming Example – Grade Calculator Application allows the user to enter the points a student earns on 4 projects and 2 tests Totals the points earned and calculates grade Total Points Earned Grade A B C D below 240F Displays total points and grade earned

27 Microsoft Visual Basic.NET: Reloaded TOE Chart

28 Microsoft Visual Basic.NET: Reloaded User Interface

29 Microsoft Visual Basic.NET: Reloaded Objects, Properties, and Settings

30 Microsoft Visual Basic.NET: Reloaded Objects, Properties, and Settings ( continued )

31 Microsoft Visual Basic.NET: Reloaded Tab Order

32 Microsoft Visual Basic.NET: Reloaded PseudoCode btnExit Click event procedure Close application btnAssignGrade Click event procedure 1.repeat while the number of projects counter is less than 5 if the points earned is numeric add the project points to the total points accumulator add 1 to the number of projects counter else display an appropriate message in a message box end if end repeat (continued on next slide)

33 Microsoft Visual Basic.NET: Reloaded PseudoCode ( continued ) 2. repeat while the number of tests counter is less than 3 get the points earned on the test if the points earned is numeric add the test points to the total points accumulator add 1 to the number of tests counter else display an appropriate message in a message box end if end repeat (continued on next page)

34 Microsoft Visual Basic.NET: Reloaded PseudoCode ( continued ) 3. Assign the grade based on the total points earned value: >= 360 assign A as the grade >= 320 assign B as the grade >= 280 assign C as the grade >= 240 assign D as the grade <240 assign F as the grade 4. Display the total points earned in lblTotalPoints 5. Display the grade in lblGrade

35 Microsoft Visual Basic.NET: Reloaded Code

36 Microsoft Visual Basic.NET: Reloaded Code ( continued )

37 Microsoft Visual Basic.NET: Reloaded Summary Three programming structures are sequence, selection, and repetition Repetition (loop) allows program to repeatedly process one or more program instructions Pretest loops test before program instructions Posttest loops test after program instructions and will always be processed at least once Pmt function calculates payment on a loan

38 Microsoft Visual Basic.NET: Reloaded Summary ( continued ) The condition in a loop evaluates to a Boolean variable While processes loop instructions while the condition is true Until processes loop instructions until the condition becomes true Use a counter or accumulator to calculate subtotals, totals and averages Counters and accumulators must be initialized and updated

39 Microsoft Visual Basic.NET: Reloaded Summary ( continued ) InputBox Function displays a dialog box that displays a message, an OK button, a Cancel button, and an input area. Test for possible division by zero to prevent an error ending the program prematurely