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
DYNAMIC LINK LIBRARY - DLL   The DLL are files which can be called when required by the other program that is running in the computer. The DLL files which support the specific

Deleting Handlers With Class Wizard: The handler can be deleted by using the class wizard. The class wizard will delete the prototype and message map entry. The user should ma

i need code for assignment problem of operational research in vb


i need sample balance sheet form in vb.net

Explain difference, Generic Variable: Create Object Ex:-Ole-Automation . No need refer the object library. What is Specific Variable: Binding Procedure Early & Late Binding ( Can


I am a beginner in Visual basic 2012 and making a data management programme with visual basic 2012 as front end and MySql as back end. I want to filter data grid view table with Li

Dialog Based Application: (A) Dialog Based Application to demonstrate Animate Control: 1. Build a dialog based application. 2. Design the dialog as shown. 3. Place

We are need of VB.NET Dynamically Created Gridview with Textboxes, DDLs Utilizing VB code in ASP.NET I dynamically create a calendar showing either 3 or 6 or 9 or 12 months, dep