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