Home »
VB.Net »
VB.Net Programs
VB.Net program to print the HEX values of numbers from 1 to 15 using the GoTo statement
Here, we are going to learn how to print the HEX values of numbers from 1 to 15 using the GoTo statement in VB.Net?
Submitted by Nidhi, on December 03, 2020 [Last updated : March 05, 2023]
Printing the HEX values of numbers from 1 to 15 using the GoTo statement in VB.Net
Here, we will print the HEX values of numbers from 1 to 15 using the "GoTo" statement and Hex() function. (Read also: Computer number systems
Program/Source Code:
The source code to print the HEX values of numbers from 1 to 5 using the "GoTo" statement is given below. The given program is compiled and executed successfully.
VB.Net code to print the HEX values of numbers from 1 to 15 using the GoTo statement
'VB.Net program to print the Hex values of numbers
'from 1 to 15 using "GoTo" statement.
Module Module1
Sub Main()
Dim num As Integer = 0
MyLabel:
num = num + 1
If num <= 15 Then
Console.WriteLine("Num:{0}, Hex value:{1}", num, Hex(num))
GoTo MyLabel
End If
End Sub
End Module
Output:
Num:1, Hex value:1
Num:2, Hex value:2
Num:3, Hex value:3
Num:4, Hex value:4
Num:5, Hex value:5
Num:6, Hex value:6
Num:7, Hex value:7
Num:8, Hex value:8
Num:9, Hex value:9
Num:10, Hex value:A
Num:11, Hex value:B
Num:12, Hex value:C
Num:13, Hex value:D
Num:14, Hex value:E
Num:15, Hex value:F
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created a variable num of Integer type, which is initialized with 0. Then we created the label MyLabel, which is used to transfer program control using the "GoTo" statement. Then we increased the value of variable num by one till 5.
If num <= 15 Then
Console.WriteLine("Num:{0}, Hex value:{1}", num, Hex(num))
GoTo MyLabel
End If
In the above code, program control will transfer each time until the value of variable num is less than equal to 15 and print the number and its corresponding HEX value on the console screen.
VB.Net Basic Programs »