Ruby - Loops and Iteration
What is the output of this Ruby code?
i = 0
while i < 3
i += 1
if i == 2
redo
end
puts i
endi = 0
while i < 3
i += 1
if i == 2
redo
end
puts i
endi == 2, redo repeats the current iteration without incrementing i again, causing the loop to print 2 repeatedly.i is not changed inside the redo loop, it never moves past 2, causing an infinite loop printing 2 repeatedly.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions