Shop OBEX P1 Docs P2 Docs Learn Events
A question about comparing variables — Parallax Forums

A question about comparing variables

PannPann Posts: 6
edited 2011-01-27 10:06 in BASIC Stamp
I need to be able to find the lowest of 5 different variables. At this point I've done it with the"brute force method" by using a crapload of IF/THEN statements. It works, but it is incredibly messy. I'm just wondering if there is a simpler, more elegant way of doing this.

Thanks

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-01-27 01:11
    Do you need to know which of the variables has the lowest value? Or do you just need to know what the lowest value is? If the latter, do this:
    lowest_value = v1 MAX v2 MAX v3 MAX v4 MAX v5
    

    -Phil
  • PannPann Posts: 6
    edited 2011-01-27 02:06
    Thank you Phil. I need to know which variable has the lowest value. I'll file your suggestion away for future reference though, because I'm sure I'll need it sometime in the future.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-01-27 09:51
    Okay, then do this:
    LOOKDOWN v1 MAX v2 MAX v3 MAX v4 MAX v5,  [v1, v2, v3, v4, v5], which
    

    which will take on a value from 0 to 4, depending upon which variable is lowest.

    -Phil
  • PannPann Posts: 6
    edited 2011-01-27 10:06
    Absolutely Awesome!! Thank you Phil!
Sign In or Register to comment.