Break, Next, and Redo

Ruby provides control keywords to manage loop execution:

  • break: Exits the loop early
  • next: Skips to the next iteration
  • redo: Repeats the current iteration

Example:

for i in 1..5
  next if i == 3
  break if i == 4
  puts i
end

Output: 1, 2

← PrevNext →