Shop OBEX P1 Docs P2 Docs Learn Events
Greater than and less than Code — Parallax Forums

Greater than and less than Code

Brian_BBrian_B Posts: 842
edited 2008-09-01 23:59 in Propeller 1
I'm trying to make a descion if the value of a variable is between 1 and 8. I've tried a couple differnt ways but I can't get it to work ,here is one sample

code.......
IF variable1 =<1 & =>8
do somthing
ELSE
do somthing differnt

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thank's Brian



·"Imagination is more important than knowledge..." ·· Albert Einstein

www.PropelX.com

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-09-01 20:07
    You need: IF variable =< 1 AND variable => 8

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-09-01 20:08
    I think you have it backward. Here is a couple of options
    if variable>0 and variable<9
      doit
    else 
      dontdoit
    
    or
    
    case variable
      1..8:
        doit
      other:
       dontdoit
    
    



    I have just lately started using case and find it very handy for some things.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-01 21:39
    how about this bit of code:
    if (variable - 1) >> 3
      code for variable not between 1 and 8
    else
      code for variable between 1 and 8
    

    This is mathmatical form of the logical expression, a result of 0 (FALSE) indicates the variable is between 1 and 8. Don't know which form is faster.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 9/1/2008 9:44:52 PM GMT
  • Brian_BBrian_B Posts: 842
    edited 2008-09-01 23:59
    Thanks' Guys,
    I used Phils version just to get it done ,but I plan on checking into the other ones

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian



    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    www.PropelX.com
Sign In or Register to comment.