Shop OBEX P1 Docs P2 Docs Learn Events
If conditional statement — Parallax Forums

If conditional statement

What is wrong with this IF statement's AND conditional..If !((iHour == iHsoak) && (iMin == iMsoak) && (iSec == iSsoak))
It keeps pointing at the second & and says(Expected an expression term)

Comments

  • Is this for Spin or C? Spin does not have a && operator. Use AND for logical expressions, and & for bitwise operations.

    -Phil
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-07-24 19:32
    Assuming this is Spin you should use AND instead of &&.  Oh, and you probably want NOT instead of !.  So in Spin it would be
    Ifnot ((iHour == iHsoak) AND (iMin == iMsoak) AND (iSec == iSsoak))
    In C it would be
    if (!((iHour == iHsoak) && (iMin == iMsoak) && (iSec == iSsoak)))
  • No, AND is not equivalent to && in Spin.

    AND is a boolean operator that evaluates both the left and right sides, and then ands them together.
    && is a short circuit operator that evaluates the left side and if that side is true, evaluates the right side.

    Ignoring the (!), you need to write:
    if (iHour == iHsoak)
      if (iMin == iMsoak)
        if (iSec == iSsoak)
          <<your code here>>
    
Sign In or Register to comment.