VB 6 While Loop - Notesformsc

NotesforMSc
  • Home
  • Computer Science
  • Programming
  • Mathematics
  • Solved Examples
Download PDF 🔍
  1. Home
  2. Uncategorized
  3. VB 6 While Loop
Search for: VB 6 While Loop Posted on October 1, 2019 by admin

Like many programming languages out there, VB 6 also has loop control statements. In this article, you will learn about While loop which helps in repeating a block of code until loop is terminated.

Syntax: While Loop

The general structure of while loop is given below.

While condition [expression or statements] Wend

The condition is very important in while loop because that is what decides when the loop will be terminated.

Consider the example below.

Dim index As Integer index = -1; While index < 10 MsgBox (index + 2) Wend

In the example above, we have put a condition for while loop that the loop should continue until index variable is equal to or greater than 10.

Example Program:

Dim Sum As Integer, i As Integer i = 0; While i < 10 Sum = Sum + i i = i + i Wend MsgBox ("The Value of Sum is " + Sum)

Output – While Loop

The program loop through and add the value of i to Sum which is incremented by 1 at each iteration.

Output - Sum While Loop
Figure 1 – Output – Sum While Loop
PreviousNext
Advertisements
Go to mobile version

Từ khóa » Visual Basic 6.0 While Loop Example