Number repeated Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


Exercise:

Number repeated 13


Objetive:

Write a Visual Basic (VB.net) program which asks for a number and an amount, and shows that number repeated as many times as the user has indicated, as in the following example:

Enter a number: 4
Enter an amount: 5

44444

You must display it three times: first using "while", then "do-while" and finally "for".


Code:

Imports System
Public Class exercise29
    Public Shared Sub Main()
        Dim num, amount As Integer
        Dim i As Integer
        Console.Write("Enter a number: ")
        num = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter an amount: ")
        amount = Convert.ToInt32(Console.ReadLine())

        For i = 0 To amount - 1
            Console.Write(num)
        Next

        Console.WriteLine()
        i = 0

        While i < amount
            Console.Write(num)
            i += 1
        End While

        Console.WriteLine()
        i = 0

        Do
            Console.Write(num)
            i += 1
        Loop While i < amount
    End Sub
End Class