FreeBasic Continue Keyword
last modified June 23, 2025
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.
Basic Definition
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's often used with conditional statements to skip specific cases without exiting the entire loop.
Continue in For 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.
Continue in While Loop
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.
Continue in Do Loop
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 with Nested Loops
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's directly
contained.
Continue with Conditional Logic
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.
Continue in Infinite Loop
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.
Continue vs Exit
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.
Best Practices
- Clarity: Use
Continuewhen it makes logic clearer than nested Ifs. - Moderation: Avoid overusing
Continueas it can make flow harder to follow. - Comments: Document why iterations are being skipped.
- Alternatives: Consider If-Else when logic is simple.
- Initialization: Ensure loop variables are updated before Continue.
This tutorial covered the FreeBasic Continue keyword with practical
examples showing its usage in different loop scenarios.
Author
List all FreeBasic Tutorials.