Multiples Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


Exercise:

Multiples 20


Objetive:

Create a Visual Basic (VB.net) program to write on screen the numbers from 1 to 500 that are multiples of 3 and also multiples of 5 (hint: use the remainder of the division).


Code:

Imports System
Public Class Exercise28
    Public Shared Sub Main()
        Dim i As Integer = 1

        While i <= 500
            If (i Mod 3 = 0) AndAlso (i Mod 5 = 0) Then Console.Write("{0} ", i)
            i += 1
        End While
    End Sub
End Class

Public Class Exercise28
    Public Shared Sub Main()
        Dim i As Integer = 1

        For i = 1 To 500
            If (i Mod 3 = 0) AndAlso (i Mod 5 = 0) Then Console.Write("{0} ", i)
        Next
    End Sub
End Class

Public Class Exercise28
    Public Shared Sub Main()
        For i As Integer = 15 To 500 Step 15
            Console.Write("{0} ", i)
        Next
    End Sub
End Class