Repeating statements while a condition is true, Visual Basic Programming

Assignment Help:

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


Related Discussions:- Repeating statements while a condition is true

Attributes, departmental store attributes

departmental store attributes

Do until loop statement , Do Until Loop Statement: The statements with...

Do Until Loop Statement: The statements within the do...until loop block executes till the condition given in until become true. The working of do...until loop is elaborated w

Adding events in visual basic , Adding Events in VB   For adding the e...

Adding Events in VB   For adding the events in VB, first double click on the command button with the caption hello. The Private Sub command1_Click () and End Sub would be

Variant subtypes, Beyond the simple string or numeric classifications, Vari...

Beyond the simple string or numeric classifications, Variant can make added distinctions regarding the specific nature of numeric information. For instance, you can have numeric in

Sum of numbers Calculator with Tryparse, I need assistance with writing the...

I need assistance with writing the Tryparse I have 98% of the assignment done.

How to, need general help in pseudo code

need general help in pseudo code

Select case - control statement, Select Case: The Select Case is used ...

Select Case: The Select Case is used for handling the multiple paths. The Select Case computes the expression and depending on the value of the equivalent Case statement execu

Modeless dialog, MODELESS DIALOG The Dialog boxes are either modal or m...

MODELESS DIALOG The Dialog boxes are either modal or modeless. The modal dialog box should be closed (Unloaded or hidden) before you can continue the working with the rest of t

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd