1st Assignment in Computer Programming
1st Assignment in Computer Programming
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.
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
Console.WriteLine(mySecondNumber)
Loop
Console.ReadLine()
b) Do Until Loop
Dim myNumber As Integer = 0
Do Until myNumber = 5
Console.WriteLine("Pick a number between 1 and 6")
myNumber = Console.ReadLine()
If myNumber = 5 Then
Console.WriteLine("Yes 5, it is!")
Else
Console.WriteLine("Oops that's not the lucky number!")
End If
Loop
Console.ReadLine()