Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between && and and in ruby.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 154
    Comment on it

    Ruby supports both && as well as and.


    The basic difference between these 2 lies in their precedence order.

    && has higher preference than and.
    and has lower preference than = unlike && which has higher preference than =

    The major difference comes while evaluating the boolean expressions.


    For ex:-

    as we know = has higher preference than and, so while evaluating the below statement a is assigned as true

    >> a = true and false
    => false
    >> puts a
    true
    

    Now as && has higher preference than =, so firstly the expression is evaluated and then it assigned to a, thus a is set as false

    >> a = true && false
    => false
    >> puts a
    false
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: