Recall & Review
beginner
What does the
break keyword do inside a Ruby loop?It immediately stops the loop and exits it, continuing execution after the loop.
Click to reveal answer
beginner
How does
next behave inside a Ruby loop?It skips the rest of the current loop iteration and moves to the next iteration.
Click to reveal answer
intermediate
What is the purpose of
redo in a Ruby loop?It restarts the current iteration of the loop without re-evaluating the loop condition or moving to the next element.
Click to reveal answer
beginner
Given this code snippet, what will be printed?
i = 0 while i < 3 i += 1 next if i == 2 puts i end
It will print:
1
3
Because when i is 2,
next skips the puts and moves to the next iteration.Click to reveal answer
intermediate
Explain the difference between
redo and next in Ruby loops.next skips to the next iteration, moving forward in the loop. redo repeats the current iteration without moving forward or checking the loop condition again.Click to reveal answer
What happens when
break is executed inside a Ruby loop?✗ Incorrect
break stops the loop immediately and exits it.Which keyword skips the rest of the current iteration and moves to the next one in Ruby?
✗ Incorrect
next skips the rest of the current iteration and moves to the next.What does
redo do inside a Ruby loop?✗ Incorrect
redo repeats the current iteration without advancing or checking the loop condition.In Ruby, which keyword would you use to restart the current loop iteration without changing the loop variable?
✗ Incorrect
redo restarts the current iteration without changing the loop variable.What will this Ruby code print?
3.times do |i|
if i == 1
break
end
puts i
end✗ Incorrect
When i is 1,
break stops the loop, so only 0 is printed.Describe how
break, next, and redo control the flow inside Ruby loops.Think about whether the loop stops, skips forward, or repeats.
You got /3 concepts.
Give an example scenario where using
redo inside a loop is helpful.Consider when you want to try the same step again without advancing.
You got /3 concepts.