Repetitive structures Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


Exercise:

Repetitive structures 22


Objetive:

Create a Visual Basic (VB.net) program to ask the user for two numbers and display the numbers between them (both included), three times: using "for", using "while" and using "do while"

Enter first number: 6
Enter last number 12

6 7 8 9 10 11 12
6 7 8 9 10 11 12
6 7 8 9 10 11 12


Code:

Imports System
Public Class exercise37
    Public Shared Sub Main()
        Dim number, number2 As Integer
        Dim i As Integer
        Console.Write("Enter first number: ")
        number = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter last number: ")
        number2 = Convert.ToInt32(Console.ReadLine())

        For i = number To number2
            Console.Write("{0} ", i)
        Next

        Console.WriteLine()
        i = number

        While i <= number2
            Console.Write("{0} ", i)
            i += 1
        End While

        Console.WriteLine()
        i = number

        Do
            Console.Write("{0} ", i)
            i += 1
        Loop While i <= number2

        Console.WriteLine()
    End Sub
End Class