Is repeat until nil an infanite loop?
✓ ANSWER ACCEPTED
Is repeat until nil an infanite loop?
1 answer
✓ Accepted answer
Yes.
repeat loops work similarly to while loops, with two differences:
They only check the condition after running the first time (
whileloops act likeifstatements for the first time)repeatloops stop on a truey value (untilimplies you are waiting for something) whilewhileloops stop on a falsey value.
There are two "falsey" values: false and nil. All others are "truey".
So,
repeat until nil is the same as the perhaps more recognizable repeat until false
Since the condition nil (or false) is a constant and always falsey, it can never change to indicate the loop will stop. So the loop is infinite and will continue on until a break or return.
This discussion is preserved as it was. New answers, comments, and votes are closed.
