ADVERTISEMENT
ADVERTISEMENT

VB.Net program to print the table of given number using GoTo statement

Here, we are going to learn how to print the table of given number using GoTo statement in VB.Net?
Submitted by Nidhi, on December 03, 2020

Here, we will read a number from the user and then print the table of the given number using the "GoTo" statement on the console screen.

Program/Source Code:

The source code to print the table of the given number using the "GoTo" statement is given below. The given program is compiled and executed successfully.

'VB.Net program to print the table of given 
'number using "GoTo" statement. 

Module Module1

    Sub Main()
        Dim count As Integer = 0
        Dim num As Integer = 0

        Console.Write("Enter number: ")
        num = Integer.Parse(Console.ReadLine())
MyLabel:

        count = count + 1

        If count <= 10 Then
            Console.WriteLine("{0}X{1}={2}", num, count, num * count)
            GoTo MyLabel
        End If
    End Sub
    
End Module

Output:

Enter number: 4
4X1=4
4X2=8
4X3=12
4X4=16
4X5=20
4X6=24
4X7=28
4X8=32
4X9=36
4X10=40
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 two variables num and count of Integer type that are initialized with 0. Then we created the label MyLabel, which is used to transfer program control using the "GoTo" statement. Then we read the value of variable num from the user. Then we increased the value of variable count by one to 10.

If count <= 10 Then
    Console.WriteLine("{0}X{1}={2}", num, count, num * count)
    GoTo MyLabel
End If

In the above code, program control will transfer each time until the value of variable count is less than equal to 10 and print the table of a given number by multiplying num by count on the console screen.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.