Loop: repeat, while, break, and continue
Use the other two loop modes and leave a loop early. Time: 15 minutes.
repeat: a fixed count
while: repeat while a condition holds
The condition is checked before each pass. The body must change the value it tests, otherwise the loop only stops at max.
repeat and while loops don’t have loop.item, so leave it out of uses.
break and continue
Inside a loop body, then accepts two special targets:
then: | Effect |
|---|---|
break | Leave the loop. The run continues after the loop |
continue | Skip the rest of this pass and start the next one |
Outside a loop, the run fails: ‘break’ is only valid inside a loop.
A common pattern is a Decision inside the body whose branches end in then: continue or then: break:
Countdown runs work once (done_at: 1), then leaves the loop because of then: break. Without break, it would stop at max: 5, because steps.start.more never changes.
Set max: 101 on any loop, then save and run it. What happens? Then try a loop of 60 nested inside another loop of 2.