0% found this document useful (0 votes)
6 views2 pages

Chapter-2 VB6 Loops Tutorial

The document explains three types of looping statements in Visual Basic 6.0: Do While...Loop, Do Until...Loop, and While...Wend. Each loop type is described with its usage, syntax, and examples, along with a summary table highlighting their conditions and capabilities. While Do While and Do Until loops are flexible and allow for exit statements, While...Wend is simpler but has limitations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Chapter-2 VB6 Loops Tutorial

The document explains three types of looping statements in Visual Basic 6.0: Do While...Loop, Do Until...Loop, and While...Wend. Each loop type is described with its usage, syntax, and examples, along with a summary table highlighting their conditions and capabilities. While Do While and Do Until loops are flexible and allow for exit statements, While...Wend is simpler but has limitations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Looping Statements in Visual Basic 6.

0 (VB6)

1. Do While...Loop

Used when: You want to repeat a block of code while a condition is true.

Syntax:

Do While condition
' Code to repeat
Loop

Example:

Dim i As Integer
i=1

Do While i <= 5
MsgBox "Number is " & i
i=i+1
Loop

Note: The condition is checked before the loop runs.

2. Do Until...Loop

Used when: You want to repeat a block of code until a condition becomes true.

Syntax:

Do Until condition
' Code to repeat
Loop

Example:

Dim i As Integer
i=1

Do Until i > 5
MsgBox "Number is " & i
i=i+1
Loop

Note: The loop stops when the condition becomes true.


3. While...Wend

Used when: You want to repeat code while a condition is true. It's an older, simpler loop
form (less flexible).

Syntax:

While condition
' Code to repeat
Wend

Example:

Dim i As Integer
i=1

While i <= 5
MsgBox "Number is " & i
i=i+1
Wend

Limitations:
- You can’t use `Exit While` or include `DoEvents` easily.
- `While...Wend` is mostly replaced by `Do While...Loop` in modern VB coding.

Summary Table

Loop Type Condition Checked Loop Continues Can Use Exit


When Statement?
Do While...Loop Before loop Condition is True Yes
Do Until...Loop Before loop Condition is False Yes
While...Wend Before loop Condition is True No

You might also like