Ticket Created
over 3 years ago

CIQQA-1312

int and logical &&

4.1.3 win/eclipse

var x = 2, y= 4;
if(x)         {LOG.println(true);} else {LOG.println(false);}
if(y)         {LOG.println(true);} else {LOG.println(false);}
if(x && y)    {LOG.println(true);} else {LOG.println(false);}

prints

true
true
false <--- bug

Parents
  • Not to state the obvious but, the problem isn't with if statements -- they actually work the way the doc in your screenshot says.

    The problem is with the unexpected and inconsistent behavior of && and ||, for numbers.

    Monkey C's && acts like C's &: A && B => A & B (with short circuiting, afaik)

    Monkey C's || acts like JavaScript's ||: A || B => A ? A : B (with short circuiting, afaik)

    The other ridiculous thing (related to the above) is this:

    var x1 = null;
    var y1 = 5;
    if (x1) { // this is fine
    }
    if (y1) { // this is fine
    }
    if (y1 || x1) { //this is fine
    }
    if (x1 && y1) { //this is fine
    }
    if (y1 && x1) { //this is a type error
    }
    if (x1 || y1) { //this is a type error
    }
Comment
  • Not to state the obvious but, the problem isn't with if statements -- they actually work the way the doc in your screenshot says.

    The problem is with the unexpected and inconsistent behavior of && and ||, for numbers.

    Monkey C's && acts like C's &: A && B => A & B (with short circuiting, afaik)

    Monkey C's || acts like JavaScript's ||: A || B => A ? A : B (with short circuiting, afaik)

    The other ridiculous thing (related to the above) is this:

    var x1 = null;
    var y1 = 5;
    if (x1) { // this is fine
    }
    if (y1) { // this is fine
    }
    if (y1 || x1) { //this is fine
    }
    if (x1 && y1) { //this is fine
    }
    if (y1 && x1) { //this is a type error
    }
    if (x1 || y1) { //this is a type error
    }
Children
No Data