41. What is the output of the given code?
if 11>2
puts "Eleven is greater than two"
end
print "You'r right"
if 11>2
puts "Eleven is greater than two"
end
print "You'r right"
42. 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
if 79>78
puts "True".upcase
if 9>8
puts "True".reverse
if 7==7
puts "equal".downcase
end
end
end
43. 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
if 79>78
puts "True".upcase
if 9>8
puts "True".Upcase
if 7==7
puts "equal".downcase
end
end
end
44. If statement inside if statement is called Nested if statements.
45. 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
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
46. It's a good habit to give two spaces between if statement and condition.
47. What is the use of else statement?
48. Is the following syntax correct?
if conditional
code...
elsif conditional
code..
else
code
end
if conditional
code...
elsif conditional
code..
else
code
end
49. What is the output of the given code?
if 1>2
puts "false"
else
puts "True"
if 1>2
puts "false"
else
puts "True"
50. What is the output of the code?
if 1>2
puts "false"
end
else
puts "True"
end
if 1>2
puts "false"
end
else
puts "True"
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.