Last modified April 20, 2026
The FreeBasic Continue keyword is a loop control statement that
skips the current iteration and moves to the next cycle. It helps in
selectively processing elements within loops based on conditions.
In FreeBasic, Continue is used within loops (For, While, Do)
to skip remaining code in current iteration. When encountered, it jumps
to the loop's condition check.
The Continue statement makes loops more flexible by allowing selective processing. It is often used with conditional statements to skip specific cases without exiting the entire loop.
This example demonstrates using Continue to skip even numbers in a For loop.
For i As Integer = 1 To 10 If (i Mod 2) = 0 Then Continue For End If Print i; " is odd" Next
The loop prints only odd numbers. When an even number is detected, Continue skips the Print statement. The loop then proceeds to next value.
Here we use Continue to skip processing negative numbers in a While loop.
Dim n As Integer = -5 While n <= 5 If n < 0 Then n += 1 Continue While End If Print "Processing"; n n += 1 Wend
The loop processes only non-negative numbers. When negative, it increments n and skips to next iteration. Note we must increment n before Continue.
This example shows Continue in a Do loop to skip vowels in string
processing.
Dim s As String = "FreeBasic"
Dim i As Integer = 0
Do While i < Len(s)
Dim c As String = Mid(s, i + 1, 1)
If InStr("aeiouAEIOU", c) Then
i += 1
Continue Do
End If
Print c; " is a consonant"
i += 1
Loop
The loop processes each character, skipping vowels. When a vowel is found, it increments index and continues. Only consonants are printed.
Continue affects only the innermost loop when used in nested
structures.
For i As Integer = 1 To 3 For j As Integer = 1 To 3 If j = 2 Then Continue For End If Print "i:"; i; " j:"; j Next Next
The inner loop skips iteration when j equals 2. The outer loop continues
normally. Continue only affects the loop where it is directly
contained.
We can combine Continue with complex conditions for sophisticated
loop control.
For i As Integer = 1 To 20 If (i Mod 3 <> 0) And (i Mod 5 <> 0) Then Continue For End If Print i; " is divisible by 3 or 5" Next
This prints numbers divisible by 3 or 5. The Continue skips numbers
not matching either condition. The logic could be inverted with If-Else.
In this example, we use Continue to control an infinite loop
until a certain condition is met. The infinite loop is created by
using a Do loop without a terminating condition.
Dim count As Integer = 0 Do count += 1 If count < 5 Then Continue Do End If Print "Count reached"; count If count >= 10 Then Exit Do End If Loop
The loop skips printing until count reaches 5. After printing, it checks for
exit condition. Continue helps delay processing until criteria met.
This example contrasts Continue with Exit in loop
control.
For i As Integer = 1 To 5 If i = 3 Then 'Exit For ' Would stop the entire loop Continue For ' Skips only this iteration End If Print i Next Print "Loop finished"
With Continue, all numbers except 3 are printed. With
Exit (if uncommented), only 1 and 2 would print before loop
termination.
Continue when it makes logic clearer than nested Ifs.Continue as it can make flow harder to follow.
This tutorial covered the FreeBasic Continue keyword with practical
examples showing its usage in different loop scenarios.
My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.
List all FreeBasic Tutorials.