Home / CSE MCQs / Ruby Programming MCQs :: Ruby Programming Mathematic Operations, Loops

CSE MCQs :: Ruby Programming MCQs

  1. What is the output of the given code?

    counter = 2
    while counter < 68
      puts counter
      counter**=2
      end
  2. A.
    2 4 16 64
    B.
    2 4 16
    C.
    2 4 16 256
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  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
  4. A.
    a and b are same
    B.
    Not same
    C.
    a==b
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What is the output of the given code?

    m= 0
    loop do
        m += 1
        print m
        break if m == 10
    end
  6. A.
    12345678910
    B.
    1 2 3 4
    C.
    2 3 4 5
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What is the output of the given code?

    for num in 1..5
      puts num*num
    endx
  8. A.
    12345678910
    B.
    1 2 3 4
    C.
    1 4 9 16 25
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. What will be the output of the given code?

    boolean_1 = 77 less than 78 && 77 less than 77
    puts boolean_1
  10. A.
    True
    B.
    False
    C.
    Error
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What will the following expression evaluate to? true || false
  12. A.
    True
    B.
    False
    C.
    Error
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What is the output of the given code?

    a="hungry"
    until !a
    puts "hungry"
    a=!a
    end
  14. A.
    hungry
    B.
    Nil
    C.
    Error
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What is the output of the given code?

    m= 8
    loop do
        m += 2
        puts m
        break if m == 16
    end
  16. A.
    10 12 14 16
    B.
    Nil
    C.
    Error
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  17. What is the output of the given code?

    i = 3
    while i > 0 do
      print i
      i -= 1
    end
  18. A.
    3
    B.
    321
    C.
    Infinite loop
    D.
    3 2 1 0

    View Answer

    Workspace

    Discuss Discuss in Forum


  19. What is the output of the given code?

    a = 5
    b=10
    while a
      puts a*b
      a+=2
      b-=2
      end
  20. A.
    5 10
    B.
    50 56
    C.
    Infinite loop
    D.
    5 6 7 8 9 10

    View Answer

    Workspace

    Discuss Discuss in Forum