Vidyalelo
Ruby Programming · all questions

Control Structures in Ruby
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

120

Questions

6/6

Page

Pick an option on a question to see the right answer and solution.

The complement of while loop is until loop.

Select an option to see the answer and solution.

What is the output of the given code?
counter = 1
until counter > 10
  puts counter
counter+=1 
  end

Select an option to see the answer and solution.

What is the output of the given code?
counter = 0
until counter >= 10
  puts counter
counter+=1 
  end

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

What is the output of the given code?
a="hungry"
until !a
puts "hungry"
a=!a
end

Select an option to see the answer and solution.

What is the output of the given code?
m= 8
loop do
    m += 2
    puts m
    break if m == 16
end

Select an option to see the answer and solution.

What is the output of the given code?
m=0
loop do
    print "ruby"
    m+=1
    break if m==5
end

Select an option to see the answer and solution.

What is the output of the given code?
m=0
loop do
    puts m*10
    m+=1
    break if m==5
end

Select an option to see the answer and solution.

What is the output of the given code?
m=0
loop do
    puts 101
    m+=1
    break if m==5
end

Select an option to see the answer and solution.

What is the output of the given code?
m=5
loop do
    m-=1
    break if m==0
end

Select an option to see the answer and solution.

What is the output of the given code?
for num in 1...5
  puts num
end

Select an option to see the answer and solution.

What does the 1...10 indicate?

Select an option to see the answer and solution.

What is the output of the given code?
for num in 1..3
  puts num
  for i in 1..2
  puts num*i
  end
end

Select an option to see the answer and solution.

What is the output of the given code?
m= 0
loop do
    m += 1
    print m
    break if m == 10
end

Select an option to see the answer and solution.

What is the output of the given code?
for num in 1..5
  puts num*num
end

Select an option to see the answer and solution.

What is the output of the given code?
for num in 1..3
  puts num*num
  m= 0
loop do
    m += 1
    puts m
    break if m == 3
end
end

Select an option to see the answer and solution.

What is the output of the given code?
loop do
    m += 1
    puts m
    break if m == 3
end

Select an option to see the answer and solution.

What is the output of the given code?
i=1
for i in 5..10
puts i^2
end

Select an option to see the answer and solution.

What does the 1..10 indicate?

Select an option to see the answer and solution.

What is the output of the given code?
i=5
j=10
for i in 5..10 && j in 5..10
puts i**j
end

Select an option to see the answer and solution.