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
    • 213
    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

    1. >> a = true and false
    2. => false
    3. >> puts a
    4. 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

    1. >> a = true && false
    2. => false
    3. >> puts a
    4. false

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: