Sail E0 Webinar

MCQs

Total Questions : 10
Question 1. What is the output of the given code?counter = 2while counter < 68  puts counter  counter**=2  end
  1.    2 4 16 64
  2.    2 4 16
  3.    2 4 16 256
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> 2 4 16


The counter will increment by the power of two.
Output:
2
4
16


Question 2. What is the output of the given code?for num in 1..5  puts num*numendx
  1.    12345678910
  2.    1 2 3 4
  3.    1 4 9 16 25
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> 1 4 9 16 25


Loop till the condition is met and break when the condition is not satisfied.
Output:
1
4
9
16
25


Question 3. What is the output of the given code?a="string"b="strings"if(a==b)    print ("a and b are same")else     print "Not same"end
  1.    a and b are same
  2.    Not same
  3.    a==b
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Not same


a and b are not similar hence the else condition will get executed.
Output:
Not same


Question 4. What is the output of the given code?m= 0loop do    m += 1    print m    break if m == 10end
  1.    12345678910
  2.    1 2 3 4
  3.    2 3 4 5
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> 12345678910


Loop till the condition is met and break when the condition is not satisfied.
Output:
12345678910


Question 5. What will be the output of the given code?boolean_1 = 77 less than 78 && 77 less than 77puts boolean_1
  1.    True
  2.    False
  3.    Error
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> False


77

Question 6. What will the following expression evaluate to?
true || false
  1.    True
  2.    False
  3.    Error
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> True


Boolean operator || evaluates to true only when both the values are true or one is true and other is false.


Question 7. What is the output of the given code?a="hungry"until !aputs "hungry"a=!aend
  1.    hungry
  2.    Nil
  3.    Error
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> hungry


Until the condition is not met execute the loop.
Output:
hungry


Question 8. What is the output of the given code?a = 5b=10while a
  1.    5 10
  2.    50 56
  3.    Infinite loop
  4.    5 6 7 8 9 10
 Discuss Question
Answer: Option B. -> 50 56


The do statement here indicates that till the while condition is true execute the instructions and will print a*b only till a
Output:
50
56


Question 9. What is the output of the given code?i = 3while i > 0 do  print i  i -= 1end
  1.    3
  2.    321
  3.    Infinite loop
  4.    3 2 1 0
 Discuss Question
Answer: Option B. -> 321


The do statement here indicates that till the while condition is true execute the instructions.
Output:
321


Question 10. What is the output of the given code?m= 8loop do    m += 2    puts m    break if m == 16end
  1.    10 12 14 16
  2.    Nil
  3.    Error
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> 10 12 14 16


Execute the loop till the condition is met.
Output:
10
12
14
16


Latest Videos

Latest Test Papers