Exercise
Break & continue
Objetive
Write a Visual Basic (VB.Net) program to write the even numbers from 10 to 20, both inclusive, except 16, in 3 different ways:
Incrementing 2 in each step (use "continue" to skip 16)
Incrementing 1 in each step (use "continue" to skip 16)
With an endless loop (using "break" and "continue")
Code
' Import the System namespace to use Console classImports System
Public Class exercise35
Public Shared Sub Main()
For i As Integer = 10 To 20 Step 2
If i = 16 Then Continue For
Console.WriteLine(i)
Next
For i As Integer = 10 To 20
If i Mod 2 = 1 Then Continue For
If i = 16 Then Continue For
Console.WriteLine(i)
Next
Dim i As Integer = 10
While True
If i = 16 Then Continue For
If i > 20 Then Exit For
Console.WriteLine(i)
i += 2
End While
End Sub
End Class