You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IsaacShelton edited this page Mar 21, 2022
·
1 revision
While Continue Statement
While continue statements are used to conditionally execute a block of code until a continue is not encountered
while continue {
// ...
}
Execution Condition
The code inside the block will be executed or be re-executed until a continue is not encountered
Usage example
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)
}
Break and Continue
Both break and continue apply to while continue statements
Loop Labels
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
}
}