Shop OBEX P1 Docs P2 Docs Learn Events
CASE vs. IF — Parallax Forums

CASE vs. IF

parskoparsko Posts: 501
edited 2006-05-11 05:08 in Propeller 1
I just re-read these sections. Wondering if anyone would like to offer an apples and oranges example for this one too?

I get the feeling that the two commands are pretty much identical. Would one (CASE?) be better suited to dealing with numbers versus the other? Is there something that fundementally sets them apart from one another?

-Parsko

Comments

  • CJCJ Posts: 470
    edited 2006-05-10 22:00
    In my eyes IF is suited for 1 to 3 possible matches where case is suitible for more possibilitys like ranges and lists

    the primary difference is readability

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Who says you have to have knowledge to use it?

    I've killed a fly with my bare mind.
  • cgraceycgracey Posts: 14,133
    edited 2006-05-11 05:08
    For multiple cases and certainly for ranges, CASE is more efficient than IF/ELSEIF/ELSE. CASE executes faster, too, for multiple checks. You can·experiment with either·construct and then check the code size difference. Use F9 to compile and then·move the cursor into your PUB/PRI to see how many Spin bytes it compiled to. This will be shown in the status bar at the bottom of the window.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
Sign In or Register to comment.