-
-
Notifications
You must be signed in to change notification settings - Fork 9
Until Break Statement
IsaacShelton edited this page Mar 21, 2022
·
1 revision
Until break statements are used to conditionally execute a block of code until a break is encountered
until break {
// ...
}
The code inside the block will be executed or be re-executed until a break is encountered
import basics
func main {
value int = 0
until break {
value = scanInt("Enter a value that isn't zero: ")
if value != 0, break
}
print("You entered " + value)
}
Both break and continue apply to until break statements
Loop labels can be used for until break loops by specifying a name for the loop label after until break
name String = ""
until break waiting_for_valid_name {
name = scan("Enter your name: ")
if isInvalid(name) {
print("Please enter a valid name!")
} else {
break waiting_for_valid_name
}
}