Repetition Structures

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
CS0004: Introduction to Programming Repetition – Do Loops.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Introduction to Computing Dr. Nadeem A Khan. Lecture 22.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Selection Structures Relational and Logical Operators; If Statements.
Chapter 5 - Visual Basic Schneider1 Chapter 5 Decisions.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
Arrays. What is the output of: Private Sub cmdButton_Click() Dim i As Integer, a(1 To 4) As integer Open "DATA.TXT" For Input As #1 For i = 1 To 4 Input.
1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.
For…Next : Nested Loop X= 0 For i = 0 To 4 For j = 0 To i-1 X=X+(i+j-1) Next j Next i How many times the inner loop is executed? What is x at the end of.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
110-K1 Iterations (1) Up to now, need to call the procedure again (e.g. click again on a command button) To repeat a piece of code: Can also use loops:
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
Array Processing: Exercises School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 10, Friday 3/28/2003)
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
Chapter four selected exercises with solutions. 4.2.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
ENGR 112 Decision Structures.
Sub procedures School of Business Eastern Illinois University © Abdou Illia, Spring 2002 (Week 6, Friday 2/21/03)
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.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
CHAPTER SIX LOOPS © Prepared By: Razif Razali 1. FORMAT OR REFRESH!! WHAT HAVE WE LEARN? Differentiate between the types of selection structure? Which.
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.
Tutorial 6 The Repetition Structure
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Sub Procedures. A Sub procedure is a block of code that is executed in response to an event. There are two types of Sub procedures, general procedures.
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
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.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
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:
Chapter six exercises
1 Looping Dale/Weems/Headington. 2 KA/JS/P Warning l Save your work often! l In the Khan Academy, JavaScript environment, infinite loops will lock up.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Higher Computing Software Development -So Far- 5/10/10.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Sub Procedures; Passing Values Back From Sub Procedures Passing by reference Passing by value.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Repetition Yonglei Tao. Display Numbers num = 1 lblDisplay.Text = num & ControlChars.NewLine num = 2 * 2 lblDisplay.Text = lblDisplay.Text & num & ControlChars.NewLine.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
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.
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.
Selection Using IF THEN ELSE CASE Introducing 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:
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.
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Repetition – For and Do While
Introducing Do While & Do Until Loops & Repetition Statements
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Alice in Action with Java
حلقات التكرار.
Case & Repetitive Statements
RECEIPT RECEIPT RECEIPT $ $ Amount Dollars $ Date No.
RECEIPT RECEIPT RECEIPT $ $ Amount Dollars $ Date No.
RECEIPT RECEIPT RECEIPT $ $ Amount Dollars $ Date No.
For...Next Statements.
Presentation transcript:

Repetition Structures Do...Loop Statement

Do...Loop Statement Do [{While | Until} condition] [statements] [Exit Do] Loop Any number of Exit Do statements may be placed anywhere in the Do…Loop as an alternate way to exit a Do…Loop. Exit Do is often used after evaluating some condition, for example, If…Then, in which case the Exit Do statement transfers control to the statement immediately following the Loop.

Do...Loop Example Private Sub cmdDisplay_Click() Dim num As Integer 'Display the numbers from 1 to 10 num = 1 Do While num <= 10 picNumbers.Print num; num = num + 1 Loop End Sub

Do...Loop Example Private Sub cmdDisplay_Click() Dim x As Integer, y As Integer x = 1 y = x * x Do While y <= 100 picOutput.Print y; x = x + 1 Loop End Sub Displays all perfect squares between 1 and 100

Private Sub cmdYears_Click() Dim balance As Single, numYears As Integer 'Compute years required to become a millionaire picWhen.Cls balance = Val(txtAmount.Text) numYears = 0 Do While balance < 1000000 balance = balance + 0.07 * balance numYears = numYears + 1 Loop picWhen.Print "In"; numYears; "years you will have a _ million dollars." End Sub

Do...Loop Statement Do [statements] [Exit Do] Loop [{While | Until} condition]

Do...Loop Example Private Sub cmdEstimate_Click() Dim amt As Single, yrs As Integer amt = 15000 yrs = 0 Do amt = amt * 1.05 - 1000 yrs = yrs + 1 Loop Until amt <= 0 picResult.Print "It takes"; yrs; "years to _ deplete the account." End Sub Subroutine calculates the years it takes to deplete a savings account with an initial balance of $15,000, paying 5% interest, and withdrawing $1000 annually.

Nested Do...Loop Example Do Do While Counter < 20 Counter = Counter + 1 If Counter = 10 Then Check = False Exit Do End If Loop Loop Until Check = False This example shows how Do...Loop statements can be nested. The inner Do...Loop statement loops 10 times, sets the value of the flag to False, and exits prematurely using the Exit Do statement. The outer loop exits immediately upon checking the value of the flag.