While And Until
Last updated
until boolean (
command
command
)until condition (
commands
)until isGoalReached (
// do things to get to goal
)// Ask for user input until a valid value is entered
userInput = null
while userInput != null (
userInput = "hello".ask()
// keep asking until the user answers
)// Wait until a sensor detects an object
objectDetected = false
until objectDetected (
robot "get_data"
objectDetected = robot.detected
)i = 0
while i < 5 (
log i
i += 1 // Valid: increment with assignment operator
)
// Alternative
i = 0
while i < 5 (
log i
i = i + 1 // Also valid: explicit assignment
)
// NOT valid:
// i++ // SyntaxError: Cannot use '+' here