VB For Loop Examples

For Loop Example

Model 1
Class Program
    Private Shared Sub Main(ByVal args As String())
        Dim n, i, j As Integer
        Console.WriteLine("Enter any number")
        n = Integer.Parse(Console.ReadLine())

        For i = 1 To n

            For j = 1 To i
                Console.Write(" " & j)
            Next

            Console.WriteLine("")
        Next
    End Sub
End Class
Model 2
Class Program
    Private Shared Sub Main(ByVal args As String())
        Dim n, i, j As Integer
        Console.WriteLine("Enter any number")
        n = Integer.Parse(Console.ReadLine())

        For i = 1 To n

            For j = 1 To i
                Console.Write(" " & i)
            Next

            Console.WriteLine("")
        Next
    End Sub
End Class

Model 3
Class Program
    Private Shared Sub Main(ByVal args As String())
        Dim n, i, j As Integer
        Console.WriteLine("Enter any number")
        n = Integer.Parse(Console.ReadLine())

        For i = 1 To n

            For j = 1 To i
                Console.Write(" #")
            Next

            Console.WriteLine("")
        Next
    End Sub
End Class


©Copyright 2016 All Rights Reserved LearnDotNetHome.com