Visual Basic - Loops

Visual Basic - Loops

Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True 3 Requirements for a Successful Loop Initialize a Loop Control Variable

Test the Loop Control Variable against an Exit Condition Update the Loop Control Variable Must be approaching exit criteria Counted / For Loop Specified Number of Times

Syntax: For loopVariable = start To End [Step StepValue] Statements Next [loopVariable] [ ] means optional

Example For counter = 1 to 10 Step 1 msgBox (The current number is: & counter) Next Try It Write a program that uses a counted/for loop

to read in a 5 numbers (using an inputBox) and display their average in a label. Try it Again Write a program using a counted/for loop that will add the numbers from 1 50 and

display the output in a label. Write a program using a counted/for loop that will add the odd numbers from 1 50 and display the output in a label. While Loops Continue Looping While a Condition is True

Syntax: Do While (condition statement) statements Loop Pre-Test Loop In a While Loop the Loop Exit condition is

tested before the program enters the loop Pre-Test Loop If Condition is False, the Loop code may never execute of loop is 0

Minimum number of executions Example Do While (number <=10) MsgBox (The current number is: & number) number = number + 1 Loop

Try It Write a program to require the user to enter a correct password (Friday). When they enter the correct password the program will display Have a Great Week-end.

Try it Again Write a program that will calculate the number of years it will take for a given input deposit amount to increase to a million dollars at 6% annual interest. Test $100,000 should take 40 years Do Until Loop

Continues Executing Until a Condition is True Syntax Do statements Loop Until (condition)

Post Test Loop In a Do..Until Loop the loop checks Exit Condition After the Loop Executes Post Test Loop Minimum Number of Executions of Loop is 1

Example Dim strPassword Do strPassword = InputBox (Enter Password) Loop Until (strPassword = Friday) Try It Note: All Loops can be written as Do While

Loops Practice this example using a D0 Until Loop Write a program that reads in a list of positive integers from the user until the user enters the value of -1 (a sentinel value exit value). At that time the program should

display the largest value in the input list. Review of Loops 3 Requirements for Successful Loop Initialize a Loop Control Variable Test the Loop Control Variable against an Exit Condition Update the Loop Control Variables

3 Types of Loops Counted Loop executes a specific number of times While Loop Pre-test loop Do Until Loop Post-test loop ALL Loops can be written as While Loops

Recently Viewed Presentations

  • Conditioned emotional reactions - &#x27;AS&#x27; psychology lesson updates

    Conditioned emotional reactions - 'AS' psychology lesson updates

    Watson & Rayner, 1920. aims. To investigate whether it is possible to condition a fear of an animal in a baby. To see whether that fear would be transferred to other animals and objects ? Aims. ... Conditioned emotional reactions...
  • Core Adult Learning Principles of Malcolm Knowles

    Core Adult Learning Principles of Malcolm Knowles

    January 6, 2005 To increase the success of entering students at Southern Maine Community College by embedding best practices for college transition and student engagement in first semester courses Core Adult Learning Principles of Malcolm Knowles Learner's need to know...
  • Shape from Moments - An Estimation Perspective

    Shape from Moments - An Estimation Perspective

    D.1 Experiment #1 LS-Prony method Squared Pencil method Hua-Sarkar method 0.0201 0.0196 0.0174 Shape From Moments Shape from Moments An Estimation Perspective Michael Elad*, Peyman Milanfar**, and Gene Golub* SIAM 2002 Meeting MS104 - Linear Algebra in Image Processing July...
  • Phonics in Action KS1 Meeting Tuesday 8th October

    Phonics in Action KS1 Meeting Tuesday 8th October

    How we teach phonics and word recognition through the Read Write Inc. Scheme. Example RWI 10 Minute speed sound lesson. Using the RWI books. How you can support your child's phonics development at home . Year 1 Phonics Screening. ......
  • Cardiac &amp; Smooth Muscle - Bellarmine University

    Cardiac & Smooth Muscle - Bellarmine University

    Cardiac & Smooth Muscle By: Daniel Dierfeldt Molecular Biology Cardiac Muscle Involuntary and striated muscle Cardiocyte = Muscle Cell of the Heart Short, thick, branched cells Each cell has only 1 nucleus Cardiac Muscle ~10-20μm in diameter ~50-100μm in length...
  • Earth Systems - Coral Springs Charter School

    Earth Systems - Coral Springs Charter School

    What is Earth? Scientists divide Earth into systems to help them better understand the planet. The outermost Earth system is an invisible layer of gases that surrounds the planet. Below the layer of gases are the systems that contain Earth's...
  • CASUALTY EVACUATION OPERATIONS PURPOSE The purpose of this

    CASUALTY EVACUATION OPERATIONS PURPOSE The purpose of this

    Platoon leaders should designate both a primary and alternate aid and litter team within each squad. When conducting patrols, it is possible that you could receive a casualty due to either an accident or hostile action. One rapid method of...
  • TAX RATES FOR TAX YEAR 2017 - Tipu Associates

    TAX RATES FOR TAX YEAR 2017 - Tipu Associates

    1. Sale against cash of any instrument including demand draft, payment order, CDR, STDR, SDR, RTC, or any other instrument of bearer nature or of receipt of cash on cancellation of any of these instruments (except in case of inter-bank...