61. The elsif statement can add many alternatives to if/else statements.
62. What is the output of the given code?
counter=6
if counter<=5
puts (counter)
counter=counter+1
puts (counter)
elsif counter>5
puts (counter)
counter=2*counter
puts(counter)
else
puts(counter)
counter=counter-1
puts(counter)
end
counter=6
if counter<=5
puts (counter)
counter=counter+1
puts (counter)
elsif counter>5
puts (counter)
counter=2*counter
puts(counter)
else
puts(counter)
counter=counter-1
puts(counter)
end63. What is output of the given code?
counter=-3
if counter<=5
puts (counter)
counter=counter+1
puts (counter)
elsif counter>5
puts (counter)
counter=2*counter
puts(counter)
end
counter=-3
if counter<=5
puts (counter)
counter=counter+1
puts (counter)
elsif counter>5
puts (counter)
counter=2*counter
puts(counter)
end64. What is the output of the given code?
if !true
print "False"
elsif !true || true
print "True"
end
if !true
print "False"
elsif !true || true
print "True"
end65. What is the output of the given code?
variable = false
if variable
print "false"
elsif !variable
print "true"
end
variable = false
if variable
print "false"
elsif !variable
print "true"
end66. What is the output of the given code?
x=7
y=9
if x==y
print "equal"
elsif x>y
print "greater"
else
print "less"
end
x=7
y=9
if x==y
print "equal"
elsif x>y
print "greater"
else
print "less"
end67. What is the output of the given code?
a=true
b=false
if a && b
puts "False"
elsif a || b
puts "True"
else
puts "neither true nor false"
end
a=true
b=false
if a && b
puts "False"
elsif a || b
puts "True"
else
puts "neither true nor false"
end68. What is the output of the given code?
a=10
b=2
if a>b
a=a*b
puts (a)
elsif a<b
a=a*a+b
puts (a)
else
a=a-b
puts (a)
end
a=10
b=2
if a>b
a=a*b
puts (a)
elsif a<b
a=a*a+b
puts (a)
else
a=a-b
puts (a)
end69. Syntax for unless conditional statement is
unless conditional [then]
code
else
code
end
unless conditional [then]
code
else
code
end70. What is the output of the given code?
x=3
unless x>2
puts "x is less than 2"
else
puts "x is greater than 2"
end
x=3
unless x>2
puts "x is less than 2"
else
puts "x is greater than 2"
endRead 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.
