Question 1 of 25
Hints left: 3
Q1
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
Q2
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
Q3
Syntax for unless conditional statement is unless conditional [then] code else code end
Q4
What is the output of the given code? string = gets.chomp case string when string = "a" print "alphabet a" when string = "b" print "alphabet b" when string = "c" print "alphabet c" else print "some other alphabet" end
Q5
What is the output of the given code? age = 4 case age puts "baby" when 0 .. 2 puts "little child" when 3 .. 6 puts "child" when 7 .. 12 puts "youth" when 13 .. 18 puts "adult" else end
Q6
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
Q7
What is the output of the given code? print "2 is less than 3" unless 2>3
Q8
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
Q9
The following syntax is used for the ruby case statement. case expression when expression , expression ... then code ... else code end
Q10
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
Q11
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
Q12
What is the output of the given code? variable = false if variable print "false" elsif !variable print "true" end
Q13
The elsif statement can add many alternatives to if/else statements.
Q14
The following syntax is also used for unless conditional statement. code unless conditional
Q15
What is the output of the given code? counter=12 unless counter print counter+1 else print counter+2 end
Q16
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
Q17
What is the output of the given code? if !true print "False" elsif !true || true print "True" end
Q18
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
Q19
What is the output of the given code? hungry=false unless hungry print "Not hungry" else print "Hungry" end
Q20
The expression specified by the when clause is evaluated as the left operand. If no when clauses match, case executes the code of the else clause.
Q21
What is the output of the given code? unless true && false print "false" else print "ruby" end
Q22
What is the output of the given code? for counter in 1..5 case counter when 0 .. 2 puts counter puts "baby" when 3 .. 6 puts counter puts "little child" when 7 .. 12 puts counter puts "child" else puts counter puts "adult" end end
Q23
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
Q24
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
Q25
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