1. The complement of while loop is until loop.
2. What is the output of the given code?
counter = 1
until counter > 10
puts counter
counter+=1
end
counter = 1
until counter > 10
puts counter
counter+=1
end
3. What is the output of the given code?
counter = 0
until counter >= 10
puts counter
counter+=1
end
counter = 0
until counter >= 10
puts counter
counter+=1
end
4. What is the output of the given code?
i = 3
while i > 0 do
puts i
i -= 1
end
j = 3
until j == 0 do
puts j
j -= 1
end
i = 3
while i > 0 do
puts i
i -= 1
end
j = 3
until j == 0 do
puts j
j -= 1
end
5. What is the output of the given code?
a="hungry"
until !a
puts "hungry"
a=!a
end
a="hungry"
until !a
puts "hungry"
a=!a
end
6. What is the output of the given code?
m= 8
loop do
m += 2
puts m
break if m == 16
end
m= 8
loop do
m += 2
puts m
break if m == 16
end
7. What is the output of the given code?
m=0
loop do
print "ruby"
m+=1
break if m==5
end
m=0
loop do
print "ruby"
m+=1
break if m==5
end
8. What is the output of the given code?
m=0
loop do
puts m*10
m+=1
break if m==5
end
m=0
loop do
puts m*10
m+=1
break if m==5
end
9. What is the output of the given code?
m=0
loop do
puts 101
m+=1
break if m==5
end
m=0
loop do
puts 101
m+=1
break if m==5
end
10. What is the output of the given code?
m=5
loop do
m-=1
break if m==0
end
m=5
loop do
m-=1
break if m==0
end
Read More Section(Control Structures in Ruby)
Each Section contains maximum 100 MCQs question on Control Structures in Ruby. To get more questions visit other sections.