Skip to content
Justice Tech School

break, next and redo

break exits a loop, next skips to the next round.

Example
(1..6).each do |i|
  next if i == 2
  break if i == 5
  print i, " "
end
puts

Result

1 3 4 

Exercise

Skip a round.

 if i == 2

Quiz Test

What does next do?

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