Professional Documents
Culture Documents
Visual Programming: Statements in Visual Basic - II
Visual Programming: Statements in Visual Basic - II
Example
Dim I as integer Statements
Do Loop I=1
Do while I < = 10
Print I Relational Test
I= I+1
Block
Loop
Example – Do While Loop
• This example contains a Do While loop that asks
the user for an age. If the user enters an age less
than 10 or more than 99, the program beeps at
the error and displays another input box asking
for the age. The program continues looping,
asking for the age, as long as the user enters an
age that's out of range.
The Do While loop's action continues while the relational test is true.
Example – Do While Loop- Coding
Dim StrAge As String Get the age in a string variable
Dim Age As Integer
StrAge = InputBox ("How old are you?", "Age Ask")
If (StrAge = "") Then
End
Do While ((age < 10) Or (age >= 99))
End If
MsgBox "Your age is Out of the range"
Age = Val(StrAge) StrAge = InputBox("How old are you?", "Age Ask")
Do . Loop
The Do While loop's action continues while the relational test is true.
Do Until Loop
Concept: Whereas the Do While loop continues
executing the body of the loop as long as the
relational test is true, the Do Until loop executes
the body of the loop as long as the relational
test is false
The Do Until loop's action continues while the relational test is False.
Example – Do UntilLoop- Coding
Dim StrAge As String Get the age in a string variable
Dim Age As Integer
StrAge = InputBox ("How old are you?", "Age Ask")
If (StrAge = "") Then
End
Do Until ((Age > 10) And (Age <= 99))
End If
MsgBox "Your age is Out of the range"
Age = Val(StrAge) StrAge = InputBox("How old are you?", "Age Ask")
Do . Loop
The Do Until loop's action continues while the relational test is False
The For Loop
Example 21
Dim I as integer
• Concept: The For loop (sometimes
I=1called the For-
Next loop) also creates aFor
loop.
I = Unlike
1 To 100the Do2
Step
loops, however, the For Print
loop I“KASTHURI
repeats for a COLLEGE”
Next I
specified number of times.
Format
For CounterVar = StartVal To EndVal [Step IncrementVal]
Block of one or more
Visual Basic statements
Next CounterVar