Learn
The complement to the while
loop is the until
loop. It’s sort of like a backward while
:
i = 0 until i == 6 i = i + 1 end puts i
- In the example above, we first create a variable
i
and set it to0
(zero). - Then we execute a block of code until
i
is equal to6
. That block of code incrementsi
. - When
i
is equal to6
, the block ends. - Finally, we print
6
, the value ofi
, to the console.
Instructions
1.
On line 2, fill in the __
blank so that the loop breaks when counter
is greater than 10
.
On line 5, increment counter
like we do in the example above.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.