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
flow chart symbols

DDX - Dialog Data Exchange: The Data members can be related with specific controls in the dialog box. When the dialog box is displayed, the DDX will transfer the values into t

Events: The Controls are placed on a form and then to make them functional an "event procedure" is related with the control object. An event process is what happens in respons

Write a program that permits the user to order a product from inventory. The user selects the product and enters the quantity. If there is sufficient quantity on hand of the produc

FILE SYSTEM CONTROLS There are 3 file system controls as shown in figure. The drive list box, directory list box & the file list box. The drive list box control is used to exhi

Tab Order: The tab order stands for the order in which the controls receive focus when the user clicks the tab key. The CTRL + D can be used to set the tab order of controls.

Event-Driven Programming: The Event-driven programming allows the program to react to various inputs or events.   The action on a graphical component is an event. For il

VISUAL INTERFACE DESIGN Instead of the graphic nature of the program, only the visualness of the inter action is important. The program must not focus on the GUI. On the other

Part 1: Create an application that allows the user to enter the following employee data: First Name, Middle Name, Last Name, Employee Number, Department, Telephone Number, Telephon

GENETICS 1.         The branch genetics started in 1900 after rediscovery of Mendel's work. 2.         Gregor Johann Mendel is called Father of genetics. 3.         The t