Is repeat until nil an infanite loop?
Yes.
repeat
loops work similarly to while
loops, with two differences:
1) They only check the condition after running the first time (while
loops act like if
statements for the first time)
2) repeat
loops stop on a truey value (until
implies you are waiting for something) while while
loops 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
.