71. What is the output of the given code?
var = 1
print "1 -- Value is set\n" if var
print "2 -- Value is set\n" unless var
var = false
print "3 -- Value is set\n" unless var
var = 1
print "1 -- Value is set\n" if var
print "2 -- Value is set\n" unless var
var = false
print "3 -- Value is set\n" unless var
72. What is the output of the given code?
hungry=false
unless hungry
print "Not hungry"
else
print "Hungry"
end
hungry=false
unless hungry
print "Not hungry"
else
print "Hungry"
end
73. The following syntax is also used for unless conditional statement.
code unless conditional
code unless conditional
74. What is the output of the given code?
counter=12
unless counter
print counter+1
else
print counter+2
end
counter=12
unless counter
print counter+1
else
print counter+2
end
75. What is the output of the given code?
unless true && false
print "false"
else
print "ruby"
end
unless true && false
print "false"
else
print "ruby"
end
76. What is the output of the given code?
print "2 is less than 3" unless 2>3
print "2 is less than 3" unless 2>3
77. What is the output of the given code?
x=8
y=10
unless x>y
puts "x is less than y"
end
unless x>y+1
puts "x is less than y+1"
end
x=8
y=10
unless x>y
puts "x is less than y"
end
unless x>y+1
puts "x is less than y+1"
end
78. What is the output of the given code?
x="ruby".length
y="language".length
puts x,y
unless x>y
print "length of x is less than that of y"
end
x="ruby".length
y="language".length
puts x,y
unless x>y
print "length of x is less than that of y"
end
79. What is the output of the given code?
x=8
y=10
unless x<y
puts "x is less than y"
end
unless x>y+1
puts "x is less than y+1"
end
x=8
y=10
unless x<y
puts "x is less than y"
end
unless x>y+1
puts "x is less than y+1"
end
80. What is the output of the given code?
age = 5
case age
when 0 .. 2
puts "baby"
when 3 .. 6
puts "little child"
when 7 .. 12
puts "child"
when 13 .. 18
puts "youth"
else
puts "adult"
end
age = 5
case age
when 0 .. 2
puts "baby"
when 3 .. 6
puts "little child"
when 7 .. 12
puts "child"
when 13 .. 18
puts "youth"
else
puts "adult"
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.