Complete the code to exit the loop when the number is 5.
numbers = [1, 2, 3, 4, 5, 6] numbers.each do |num| if num == 5 [1] end puts num end
The break keyword exits the loop immediately when the condition is met.
Complete the code to skip printing the number 3 but continue the loop.
numbers = [1, 2, 3, 4, 5] numbers.each do |num| if num == 3 [1] end puts num end
The next keyword skips the current iteration and continues with the next one.
Fix the error in the code to repeat the current iteration when the number is even.
numbers = [1, 2, 3] numbers.each do |num| if num.even? [1] end puts num end
The redo keyword repeats the current iteration without moving to the next element.
Fill both blanks to skip printing 2 and stop the loop at 4.
numbers = [1, 2, 3, 4, 5] numbers.each do |num| if num == 2 [1] elsif num == 4 [2] end puts num end
Use next to skip printing 2 and break to stop the loop at 4.
Fill all three blanks to repeat the iteration for odd numbers, skip 4, and stop at 5.
numbers = [1, 2, 3, 4, 5] numbers.each do |num| if num.odd? [1] elsif num == 4 [2] elsif num == 5 [3] end puts num end
Use redo to repeat the iteration for odd numbers, next to skip 4, and break to stop at 5.
