-
-
Notifications
You must be signed in to change notification settings - Fork 9
While Statement
IsaacShelton edited this page Mar 21, 2022
·
1 revision
While statements are used to conditionally execute a block of code while a condition is true
while condition {
// ...
}
while(condition){
// ...
}
while condition, // ...
while condition // ...
while(condition) // ...
while(condition), // ...
If the condition is true
, then the code inside the block will be executed or be re-executed
import basics
func main {
value int = scanInt("Please don't enter 10: ")
while value != 10 {
value = scanInt("Please don't enter 10: ")
}
print("You entered 10, goodbye")
}
Both break
and continue
apply to while
statements
Loop labels can be used for while
loops by specifying a name for the loop label followed by :
before the condition
while game_running : !game.closeWasClicked() {
if game.isGameOver(), break game_running
}
A version of while
exists called while continue
x int = 0
while continue {
x++
if x < 10, continue
}
See while continue
for more information