← Back to Ruby Course | Chapter 6: Control Flow | Lesson 7 of 7

break, next, and redo

In this page:

  1. break, next, and redo

break, next, and redo

break exits the nearest enclosing loop entirely, next skips to the next iteration (like continue in other languages), and redo re-runs the current iteration from the start without re-checking the loop's condition. redo is rarely used but can be handy for retry-style logic within a single iteration. All three work inside while, until, for, and block-based iteration like each.

Note: redo is Ruby's least common loop control keyword -- reach for it only when you specifically need to repeat the current iteration, not move to the next one.

Example: break, next, and redo

markup
(1..10).each do |i|
  next if i.even?
  break if i > 7
  puts i
end
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.