Home / CSE MCQs / Ruby Programming MCQs :: Ruby Programming Conditional Statements

CSE MCQs :: Ruby Programming MCQs

  1. 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
  2. A.
    alphabet a
    B.
    b alphabet b
    C.
    alphabet c
    D.
    Syntax error

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What is the output of the code?

     if 1>2
       puts "false"
       end
       else
       puts "True"
       end
  4. A.
    False
    B.
    True
    C.
    Syntax error
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What is the output of the code?

    variable="true".reverse
       if variable
       puts "true"
       else
       puts "false"
       end
  6. A.
    False
    B.
    True
    C.
    Syntax error
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. What is the output of the given code?

    if !true
       print "False"
       elsif !true || true
       print "True"
       end
  8. A.
    True
    B.
    False
    C.
    Syntax eroor
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. 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
  10. A.
    false
    B.
    true
    C.
    neither true nor false
    D.
    none of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What error does the if condition gives if not terminated with end statement?
  12. A.
    Syntax error
    B.
    Unexpected end
    C.
    Expecting keyword end
    D.
    All of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What is the output of the given code?

    if 11>2
       puts "Eleven is greater than two"
       end
       print "You'r right"
  14. A.
    Eleven is greater than two
    B.
    You'r right
    C.
    Eleven is greater than two You'r right
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum


  15. What is the output of the given code?

    hungry=false
    unless hungry
     print "Not hungry"
    else
     print "Hungry"
    end
  16. A.
    Not hungry
    B.
    Hungry
    C.
    Syntax error
    D.
    None of the mentioned

    View Answer

    Workspace

    Discuss Discuss in Forum