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

For...Next and Do Loops in VB

The document discusses programming concepts related to loops in Visual Basic, specifically the For...Next loop and Do Loops. It explains how the For...Next loop iterates a specific number of times and provides an example of creating a string with numbers. Additionally, it covers Do While and Do Until loops, including examples for each type that demonstrate their functionality.

Uploaded by

alejaquiambao07
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)
16 views2 pages

For...Next and Do Loops in VB

The document discusses programming concepts related to loops in Visual Basic, specifically the For...Next loop and Do Loops. It explains how the For...Next loop iterates a specific number of times and provides an example of creating a string with numbers. Additionally, it covers Do While and Do Until loops, including examples for each type that demonstrate their functionality.

Uploaded by

alejaquiambao07
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

Aleja C.

Quiambao
Grade 9-SSP
COMPUTER PROGRAMMING
1st Assignment in 3rd Quarter

For…Next Loop
The for... next statement is an iterative, incremental loop statement used to
repeat a sequence of statements for a specific number of occurrences. ...
This looping continues until the ending condition is met or the loop is explicitly exited
with an exit or goto statement.

Example:
This example uses the For...Next statement to create a string that
contains 10 instances of the numbers 0 through 9, each string separated
from the other by a single space. The outer loop uses a loop counter variable
that is decremented each time through the loop.

Dim Words, Chars, MyString


For Words = 10 To 1 Step -1 ' Set up 10 repetitions.
For Chars = 0 To 9 ' Set up 10 repetitions.
MyString = MyString & Chars ' Append number to string.
Next Chars ' Increment counter
MyString = MyString & " " ' Append a space.
Next Words

Do Loops
The Do Loop enables you to decide whether to end the loop when the condition
stops being true or when it first become true. It also enables you to test condition at
either the start or the end of the loop.
There are two Do Loops in Visual Basic: the Do While and Do Until. The Do
While loops something which is true, and the Do Until loops until a certain condition is
met. Create a new VB Console Application and name it Do Loops.

Example:
a) Do While Loop
Dim mySecondNumber As Integer
Do While mySecondNumber < 50
mySecondNumber += 1
[Link](mySecondNumber)
Loop
[Link]()

b) Do Until Loop
Dim myNumber As Integer = 0

Do Until myNumber = 5
[Link]("Pick a number between 1 and 6")
myNumber = [Link]()

If myNumber = 5 Then
[Link]("Yes 5, it is!")
Else
[Link]("Oops that's not the lucky number!")
End If
Loop
[Link]()

You might also like