Page 141 - Open Soource Technologies 304.indd
P. 141

Unit 6: VB Control Structure



               encountered, the entire process is repeated, beginning with the testing of condition in the Do
               While statement. In other words, the statements inside the loop are repeatedly executed only as
               long as (that is, while) the condition is true. Figure 6.2 contains the pseudocode and flowchart
               for this loop.





                                                                  In the  No
                                                                 condition
                                                                  true ?

                                                                     Yes

                                                                 Execute
                                 Do while condition is true      statements
                                 processing step (s)             within
                                 Loop                            the loop





                                                                 Execute
                                                                statements
                                                                 that follow
                                                                  the loop

                               Figure 6.2:  Pseudocode and  Flowchart for a Do While  Loop.
                              1: The following program, in which the condition in the Do loop is “num
                                <=7”, displays the numbers from 1 through 7. (After the Do loop executes,
                                the value of num will be 8.)
               Private Sub btnDisplay_Click(...) Handles btnDisplay.Click
                 ‘Display the numbers from 1 to 7
                 Dim num AsInteger = 1
                 DoWhile num <= 7
                   lstNumbers.Items.Add(num)
                 num += 1    ‘Add 1 to the value of num
                 Loop
               End Sub
               [Run, and click the button. The following is displayed in the list box.]
               1
               2
               3
               4
               5
               6
               7


                                      LOVELY PROFESSIONAL UNIVERSITY                        135
   136   137   138   139   140   141   142   143   144   145   146