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

2/6

Page

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

Which of the following is used to create a range in Ruby?

Select an option to see the answer and solution.

What is the output of the following code snippet?
for i in 1..5
  print i, " "
end

Select an option to see the answer and solution.

In Ruby, what does the `break` keyword do when used within nested loops?

Select an option to see the answer and solution.

Which of the following is NOT a valid way to exit a loop in Ruby?

Select an option to see the answer and solution.

In Ruby, what does the `until` keyword do?

Select an option to see the answer and solution.

What does the `retry` keyword do when used within a loop in Ruby?

Select an option to see the answer and solution.

In Ruby, what does the `case` statement allow you to compare against?

Select an option to see the answer and solution.

In Ruby, which of the following is NOT a valid loop construct?

Select an option to see the answer and solution.

What is the purpose of the loop keyword in Ruby?

Select an option to see the answer and solution.

Which of the following is used to define a block of code that executes repeatedly until a condition is met in Ruby?

Select an option to see the answer and solution.

In Ruby, what is the purpose of the `redo` keyword?

Select an option to see the answer and solution.

Which keyword in Ruby is used to exit a loop prematurely?

Select an option to see the answer and solution.

In Ruby, which of the following is used to handle multiple conditions with one expression?

Select an option to see the answer and solution.

In Ruby, what does the `else` keyword do?

Select an option to see the answer and solution.

In Ruby, what does the `elsif` keyword do?

Select an option to see the answer and solution.

The following syntax is correct for if conditional statement.
 if condition
    code
   end

Select an option to see the answer and solution.

If expression.
The expression can be of which type?

Select an option to see the answer and solution.

What error does the if condition gives if not terminated with end statement?

Select an option to see the answer and solution.

What is the output of the following?
if 1<2
   print "one is less than two"
   end

Select an option to see the answer and solution.

What is the output of the code?
 if 11<2
   print "Eleven is less than two"
   end
   print "11 is greater"

Select an option to see the answer and solution.