0% found this document useful (0 votes)
56 views

Visual Programming: Statements in Visual Basic - II

The document discusses different types of loops in visual basic, including Do While, Do Until, and For loops. The Do While loop repeats a block of code as long as a relational test is true. The Do Until loop repeats code as long as the test is false. The For loop repeats a specified number of times, using a counter variable that increments from a start value to an end value. Examples are provided of each loop type to illustrate their syntax and usage.

Uploaded by

kannan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Visual Programming: Statements in Visual Basic - II

The document discusses different types of loops in visual basic, including Do While, Do Until, and For loops. The Do While loop repeats a block of code as long as a relational test is true. The Do Until loop repeats code as long as the test is false. The For loop repeats a specified number of times, using a counter variable that increments from a start value to an end value. Examples are provided of each loop type to illustrate their syntax and usage.

Uploaded by

kannan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Visual Programming

Statements in Visual Basic - II


Objectives

• The Do While Loop


• Examples
• The Do Until Loop
• Examples
• The For Loop
• Examples
The Do While Loop

• Concept: When a computer does something over


and over, the computer is said to be looping.
• The Do statement supports several different loop
formats.
• The Do While loop is perhaps the most common
looping statement that you'll put in Visual Basic
programs.
Format of the Do While loop
Do While (relational test)
Block of one or more Visual Basic statements
Loop
Definition: A block consists of one or more program statements.

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")

If (StrAge = "") Then


MsgBox ("Cancel Pressed")
End If
age = Val(StrAge)

l Bu tt on in the Input Box Loop


e C a nc e
Checks for th

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")

If (StrAge = "") Then


MsgBox ("Cancel Pressed")
End If
age = Val(StrAge)

l Bu tt on in the Input Box Loop


e C a nc e
Checks for th

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

You might also like