Controlling Program Flow with Looping Structures

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

Looping Structures: Do Loops
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
CS0004: Introduction to Programming Repetition – Do Loops.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Visual Basic.NET BASICS Lesson 10 Do Loops. 2 Objectives Explain what a loop is. Use the Do While and Do Until loops. Use the InputBox function. Use the.
Repeating Actions While and For Loops
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
5.05 Apply Looping Structures
Chapter 5 new The Do…Loop Statement
CHAPTER SIX Loop Structures.
CHAPTER 6 Loop Structures.
CHAPTER SIX.
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.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
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.
Chapter 12: How Long Can This Go On?
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
© 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.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
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.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
JavaScript, Fourth Edition
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
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.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
© 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?
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Controlling Program Flow with Decision Structures.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
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()
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
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.
Loop Blocks Chapter 6 Part A. Program Blocks 1.Actions- commands, messages, methods 2.Branches- decisions to be made 3.Loops- actions to be repeated.
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. 
UNIT 5 Lesson 15 Looping.
Controlling Program Flow with Looping Structures
REPETITION CONTROL STRUCTURE
Lists, Loops, Validation, and More
Repeating Program Instructions
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Chapter 5 The Do…Loop Statement
Microsoft Visual Basic 2005: Reloaded Second Edition
حلقات التكرار.
Chapter (3) - Looping Questions.
CIS 16 Application Development Programming with Visual Basic
Prepared By: Deborah Becker
Presentation transcript:

Controlling Program Flow with Looping Structures Chapter 5 Controlling Program Flow with Looping Structures

The Do…Loop Statement Is a looping structure that executes a set of statements as long as a condition is True. Iteration – repeating one or more statements Example: Dim intNum As Integer intNum = 0 Do intNum = intNum + 2 ‘Increment by 2 Loop While intNum < 10 (Do…Loop executes five times, on the fifth time intnum = 10 making the condition false)

Do…Loop While The code in the loop must be executed at least once The condition determines if the loop will be repeated (True it repeats False it leaves the loop and continue on with the program). Example: Dim intNum As Integer intNum = 0 Do while intNum < 10 intNum = intNum + 2 ‘Increment by 2 Loop

Do While …Loop Different than the Do…Loop While The condition is evaluated first before entering the loop. If condition evaluates true the loop is entered. If the condition evaluates to false the loop is skipped. The code in the loop is not guarantee to be execute at all.

Infinite Loops Is a loop that does not stop running and never becomes false. CTRL + BREAK will stop an infinite loop if one occurs

Input Boxes Is a Visual Basic predefined dialog box that has a prompt, a text box, and OK and Cancel buttons. Used to get information from the user.

Input Boxes The InputBox form is InputBox(prompt, title) Prompt represents a string Title represents a string The InputBox will return a string so you will need to have a String memory variable to hold it or you can display it with the label.

Example of Code for the InputBox Dim strTextInput As String strTextInput = InputBox(“Enter Text”, “Input Box”) Or lblLabel.Caption = InputBox(“Enter text”, “Input Box”)

Accumulators Is a numeric variable used to store a value that accumulates, or gets added to, during runtime. Example: intAccum = intAccum + value Flag or Sentinel Values are used to end a loop usually -1 or -999. Example: intNum = 0 Do while intNum <> -1 intNum = txtBox.text Loop

For…Next Statement Is a looping structure that executes a set of statements a fixed number of times. For…Next executes until a counter reaches an ending value. Unlike the Do …Loop that executes while a condition is true.

For…Next Statement Form For counter = start To end Statements Next counter Counter, start, and end are Integer variables, values, or expressions.

Components of a For…Next loop Counter is initialized to start only once when the loop first executes. Counter is compared to end before each loop iteration. Counter is automatically incremented by 1 after each iteration of the loop body.

Example of a For…Next Loop Dim intNum As Integer For intNum = 1 To 10 MsgBox intNum ‘Display message box Next intNum ‘Displays message box 10 times

Step in a For…Next Loop Step – changes the way the For…Next Loop is incremented Example: For intCount = 2 To 8 Step 2 Statements Next intCount ‘Increments the counter by 2 ‘You can decrement a counter by using negative numbers for the Step value