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

VBNET_ProgrammingConstructs

Uploaded by

chidziwosteven
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)
2 views

VBNET_ProgrammingConstructs

Uploaded by

chidziwosteven
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
You are on page 1/ 2

SELECTION

 IF...THEN…ELSE
SubMain()
Dim mark AsInteger
Console.WriteLine("ENTER A MARK")
mark = Console.ReadLine
If mark >= 50 Then
Console.WriteLine("A PASS MARK")
Else
Console.WriteLine(" A FAIL MARK")
EndIf
Console.ReadKey()
EndSub
EndModule

 CASE…SELECT
ModuleModule1

SubMain()
'Use of SELECT..CASE
Dim monthAsString
Console.WriteLine("ENTER MONTH NAME")
month = Console.ReadLine
Select Case month
Case "jan", "mar", "may", "jul", "aug", "oct", "dec"
day = 31
Case "apr", "jun", "sep", "nov"
day = 30
Case "feb"
day = 28 or 29
Case Else
Console.WriteLine("You have entered invalid month")
EndSelect
Console.WriteLine("The month {0} has {1} days", month, day)
Console.ReadKey()
EndSub
EndModule

REPETITION/LOOPS
 FOR…NEXT Loop
SubMain()
'PROGRAM TO FIND THE SUM AND AVERAGE OF 5 NUMBERS USING FOR..NEXT LOOP
Dim number, sum AsInteger
sum = 0
For Counter = 1 To 5
Console.WriteLine("ENTER YOUR NUMBER")
number = Console.ReadLine
sum = sum + number
average = sum / 5
Next Counter
Console.WriteLine()
Console.WriteLine("SUM IS: {0}", sum)
Console.WriteLine("AVERAGE IS: {0}", average)
Console.ReadKey()

1
EndSub
EndModule

 DO…LOOP UNTIL Loop


SubMain()
'AVERAGE OF 5 NUMBERS USING DO...LOOP UNTIL
Dim number
Dim sum As Integer = 0
Dim counter As Integer = 0
Dim average As Decimal
Do
Console.WriteLine("ENTER YOUR NUMBER")
number = Console.ReadLine
sum = sum + number
counter = counter + 1
Loop Until counter = 5
average = sum / 5
Console.WriteLine()
Console.WriteLine("SUM IS: {0}", sum)
Console.WriteLine("AVERAGE IS: {0}", average)
Console.ReadKey()
EndSub
EndModule

 WHILE…END WHILE Loop


SubMain()
'SUM AND AVERAGE OF 5 NUMBERS USING WHILE...ENDWHILE
Dim number, sum, c AsInteger
Dim average AsDecimal
sum = 0
c = 0
While c < 5
Console.WriteLine("ENTER YOUR NUMBER")
number = Console.ReadLine
sum = sum + number
c = c + 1
average = sum / 5
EndWhile
Console.WriteLine()
Console.WriteLine("SUM IS: {0}", sum)
Console.WriteLine("AVERAGE IS: {0}", average)
Console.ReadKey()
EndSub
EndModule

You might also like