SecondBASIC Documentation v3

Home / Command Reference / Do...Loop

Do...Loop

Description: Creates a loop that ends when a condition is met or an Exit command is executed.

Syntax:

Do [While <Condition>]
    ' code to execute
Loop [<ConditionType> <Condition>]

Part Description
<Condition> Optional. This is an expression that returns true or false.
<ConditionType> Optional. This is can either be While (loops while the condition is true) or Until (loops until the condition is true).

Notes: If a condition isn't specified, the only way to exit the loop is with the Exit command.

Example:

    Dim x As Integer
    x = 0
 
    Do
        x++
        If x = 15 Then Exit Do
    Loop
    Print x
 
    Do While x > 3
        x--
    Loop
    Print x
 
    Do
        x++
    Loop Until x = 24
    Print x
 
    Do
        x--
    Loop While x > 0
    Print x