Skip to content
Loops
step 1/5

Reading — step 1 of 5

Learn

~1 min readControl Flow

For ... Next — counted iteration:

For i As Integer = 1 To 10
    Console.WriteLine(i)
Next

For i As Integer = 10 To 1 Step -1
    Console.WriteLine(i)
Next

For Each ... In over collections:

Dim nums = {1, 2, 3, 4, 5}
For Each n In nums
    Console.WriteLine(n)
Next

While ... End While:

Dim n As Integer = 1
While n < 100
    n *= 2
End While

Do ... Loop — flexible:

Do
    line = Console.ReadLine()
Loop Until line = "quit"

Do While n < 100
    n *= 2
Loop

Exit For / Exit While / Exit Do to break. Continue For / etc. to skip to next iteration.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…