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

3/6

Page

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

What is the output of the given code?
if 11>2
   puts "Eleven is greater than two"
   end
   print "You'r right"

Select an option to see the answer and solution.

What is the output of the given code?
if 79>78
   puts "True".upcase
   if 9>8
   puts "True".reverse
   if 7==7
   puts "equal".downcase
   end
   end
   end

Select an option to see the answer and solution.

What is the output of the given code?
if 79>78
   puts "True".upcase
   if 9>8
   puts "True".Upcase
   if 7==7
   puts "equal".downcase
   end
   end
   end

Select an option to see the answer and solution.

If statement inside if statement is called Nested if statements.

Select an option to see the answer and solution.

What is the output of the given code?
x=1
    if x > 2
    puts "x is greater than 2"
    elsif x <= 2 and x!=0
    puts "x is 1"
    else
    puts "I can't guess the number"
    end

Select an option to see the answer and solution.

It's a good habit to give two spaces between if statement and condition.

Select an option to see the answer and solution.

What is the use of else statement?

Select an option to see the answer and solution.

Is the following syntax correct?
if conditional 
   code...
   elsif conditional 
   code..
   else
   code
   end

Select an option to see the answer and solution.

What is the output of the given code?
if 1>2
   puts "false"
   else
   puts "True"

Select an option to see the answer and solution.

What is the output of the code?
 if 1>2
   puts "false"
   end
   else
   puts "True"
   end

Select an option to see the answer and solution.

What is the output of the code?
variable=true
   if variable
   puts "true"
   else
   puts "false"
   end

Select an option to see the answer and solution.

What is the output of the code?
 variable="true".reverse
   if variable
   puts "true"
   else
   puts "false"
   end

Select an option to see the answer and solution.

What is the output of the code?
variable=true
   if !variable
   puts "true"
   else
   puts "false"
   end

Select an option to see the answer and solution.

What is the output of the code?
variable="true".length
   if variable
   puts "true"
   else
   puts "false"
   end

Select an option to see the answer and solution.

Which of the following is valid conditional statement?

Select an option to see the answer and solution.

What is the output of given code?
 counter=1
    if counter<=5
    puts (counter)
    counter=counter+1
    else 
    puts(counter)
    counter=counter-1
    end

Select an option to see the answer and solution.

What is the output of given code?
#counter=1
    if counter<=5
    puts (counter)
    counter=counter+1
    else 
    puts(counter)
    counter=counter-1
    end

Select an option to see the answer and solution.

It is necessary that always if should come with else block?

Select an option to see the answer and solution.

Which of the following is valid conditional statement in Ruby?

Select an option to see the answer and solution.

The elsif conditional statement is written with an expression.

Select an option to see the answer and solution.