Skip to content

Until Statement

IsaacShelton edited this page Mar 21, 2022 · 1 revision

Until Statement

Until statements are used to conditionally execute a block of code until a condition is true

until condition {
    // ...
}
until(condition){
    // ...
}
until condition,  // ...
until condition   // ...
until(condition)  // ...
until(condition), // ...

Execution Condition

If the condition is false, then the code inside the block will be executed or be re-executed

While vs Until

until is the negated version of the while statement

Usage example

import basics

func main {
    value int = scanInt("Please don't enter 10: ")
    
    until value == 10 {
        value = scanInt("Please don't enter 10: ")        
    }
    
    print("You entered 10, goodbye")
}

Break and Continue

Both break and continue apply to until statements

Loop Labels

Loop labels can be used for until loops by specifying a name for the loop label followed by : before the condition

until ready : downloadedFile.isFinished() {
    if downloadedFile.failed(), break ready
    waitForSomeTime()
}

Until Break

A version of until exists called until break

x int = 0
until break {
    if ++x == 10, break
}

See until break for more information

Clone this wiki locally