Shop OBEX P1 Docs P2 Docs Learn Events
what's a different?.. — Parallax Forums

what's a different?..

eem_murateem_murat Posts: 8
edited 2007-03-01 16:56 in BASIC Stamp
hi all,

IF (cm1>50) AND (cm2>50) AND (cm3>50) THEN .....,
IF ((cm1>50) AND (cm2>50) AND (cm3>50)) THEN....··this line has·extra ()
you thing is there a different betwen this line?· or·all of them work same?..

and ı wonder that what is the different from (&·---- and)
when ı used "&"·or · " and" they work same in uplines..

and ı write aproximately 300 lines program and it include if..then, do..while.. or lots of another loop . and ı use bs2. you think, bs2 is enough·microcontroller for my program. ı only wonder cycle speed...icon8.gif

·

Comments

  • ZootZoot Posts: 2,227
    edited 2007-03-01 16:55
    "AND" is a logical comparison (i.e., are both true?) while "&" is a bit-wise comparison. It looks like you mean to use logical comparisons in your example, so I would stick with "AND".

    These lines:
    IF (cm1>50) AND (cm2>50) AND (cm3>50) THEN .....,
    IF ((cm1>50) AND (cm2>50) AND (cm3>50)) THEN....  this line has extra ()
    



    Are functionally equivalent. Pbasic doesn't require the outside parentheses in IF..THEN statements:

    IF x = 0 THEN DoSomething
    
    



    is the same as

    IF ( x = 0 ) THEN DoSomething
    
    



    I often write such phrases WITH the parentheses, though, because I am used to languages like Perl where parentheses are required for conditional statements (in other words, to my eye it looks funny without them). But that's just me.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • ZootZoot Posts: 2,227
    edited 2007-03-01 16:56
    "AND" is a logical comparison (i.e., are both true?) while "&" is a bit-wise comparison. It looks like you mean to use logical comparisons in your example, so I would stick with "AND".

    These lines:
    IF (cm1>50) AND (cm2>50) AND (cm3>50) THEN .....,
    IF ((cm1>50) AND (cm2>50) AND (cm3>50)) THEN....  this line has extra ()
    



    Are functionally equivalent. Pbasic doesn't require the outside parentheses in IF..THEN statements:

    IF x = 0 THEN DoSomething
    
    



    is the same as

    IF ( x = 0 ) THEN DoSomething
    
    



    I often write such phrases WITH the parentheses, though, because I am used to languages like Perl where parentheses are required for conditional statements (in other words, to my eye it looks funny without them). But that's just me.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.