Skip to content
Justice Tech School

While, Until and Loop

while repeats while true, until repeats until true and loop do runs forever until break. next skips a round and redo repeats it.

Example
i = 0
while i < 3
  i += 1
end
puts i
until i == 0 do i -= 1 end
puts i
n = 0
loop do
  n += 1
  next if n == 2
  break if n > 3
  print n, " "
end
puts

Result

3
0
1 3 

Exercise

Loop until true.

 x == 0 do end

Quiz Test

What leaves a loop?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.