Repeating statements while a condition is true, Visual Basic Programming

Use the While keyword to verify a condition in a Do...Loop statement. You can verify the condition before you enter the loop (as illustrated in the following ChkFirstWhile instance), or you can verify it after the loop has run at least once (as illustrated in the ChkLastWhile instance). In the ChkFirstWhile procedure, if myNum is set to 9 rather than 20, the statements inside the loop will never run. In the ChkLastWhile process, the statements inside the loop run only once since the condition is already False.

Sub ChkFirstWhile() Dim counter, myNum counter = 0

myNum = 20

Do While myNum > 10 myNum = myNum - 1 counter = counter + 1

Loop

MsgBox "The loop made " & counter & " repetitions." End Sub

Sub ChkLastWhile() Dim counter, myNum counter = 0

myNum = 9

Do

myNum = myNum - 1 counter = counter + 1

Loop While myNum > 10

MsgBox "The loop made " & counter & " repetitions." End Sub

The above figure illustrate two example code fragments illustrating the do... loop and do while ... loop statements. In the first loop the condition is verified before executing the code however in the second loop the statements are first executed once and after that the condition is verified. In the first loop the instructions given in the loop's body will never be executed if the condition initially fails but in the second loop these instructions would be executed at least once.  The following flow chart illustrates the execution plan of the second procedure i.e. CheckLastWhile:

1225_Repeating Statements While a Condition is True.png

                Figure: Execution Plan of the Second Loop

Posted Date: 4/18/2013 5:46:49 AM | Location : United States







Related Discussions:- Repeating statements while a condition is true, Assignment Help, Ask Question on Repeating statements while a condition is true, Get Answer, Expert's Help, Repeating statements while a condition is true Discussions

Write discussion on Repeating statements while a condition is true
Your posts are moderated
Related Questions
i want to print number following pattern 1 12 123 1234

two sides are given of a sheet e.g 23*36 i want half or 1/2 of this sheet next i want 1/4(one fourth) of this sheet if sheet size is 23*36 next i want 1/8 similary as above

departmental store attributes

Software That Is Rude: The software warns the user for making the mistakes. The Message boxes pop up representing the mistake and the user will have to click the OK or CANCEL

CONTROL ARRAY The control array is a group of similar objects with similar name. Adding controls with control arrays uses less resource than simply adding the multiple controls

Visual Processing: Our mind groups the things into patterns and this allows us to process the visual information. Understanding and applying how the human mind processes the v

I need to design a logic for a program that allows a user to enter 15 numbers, then displays each number and its difference from the numeric average of the numbers entered

THREE MODELS FOR USER INTERFACE DESIGN   The 3 models for the user interface design are the implementation model, mental model &the manifest model. The Implementation Mod

The scope of a variable is finding out by where you declare it. While you declare a variable in a procedure, only code in that procedure can access or alter the value of that varia

PROGRAM TO ZOOM A RECTANGLE AS YOU DRAG 1. Generate a SDI application 2. Declare the 2 member variables clicked of Boolean type and m_ptoldpt of CPoint type. Use the class t