Shop OBEX P1 Docs P2 Docs Learn Events
low level detail on case — Parallax Forums

low level detail on case

Erik FriesenErik Friesen Posts: 1,071
edited 2008-09-11 04:16 in Propeller 1
How many time does a variable get checked in one case statement?
For example does variable get checked once or three times in the below code?

case variable
   "a":do
   "b":dontdo
   "c":doorelse

Comments

  • mparkmpark Posts: 1,305
    edited 2008-09-10 23:41
    Not sure what you mean by "checked", but the case expression (in your example, just variable, but it could be more complicated) is evaluated once; the result of that evaluation is compared up to three times (against "a", "b", and "c" -- but of course if it matches "a" it won't keep comparing).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Michael Park

    PS, BTW, and FYI:
    To search the forum, use search.parallax.com (do not use the Search button).
    Check out the Propeller Wiki: propeller.wikispaces.com/

    Post Edited (mpark) : 9/10/2008 11:50:40 PM GMT
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2008-09-11 01:31
    Right, but if the variable changes between comparisons it still uses the original, right?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-11 02:15
    Im 95% certain there is only a single evaluation of "variable".

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

    Parallax, Inc.
  • hippyhippy Posts: 1,981
    edited 2008-09-11 04:16
    Paul's correct. Once the particular choice to use has been selected the code associated with it is executed and then the entire case is over and done with.
Sign In or Register to comment.