Shop OBEX P1 Docs P2 Docs Learn Events
Limit to SPIN elseif construct — Parallax Forums

Limit to SPIN elseif construct

agsags Posts: 386
edited 2013-12-25 02:39 in Propeller 1
Merry Christmas.

I probably need to refactor my implementation of a web server. Until then, I'm battling an issue with a limitation to "elseif" in SPIN. Seems that there is a limit to 16 consecutive "elseif" statements in a single conditional clause. (sounds like spin only reserves 4 bits?). I am comparing a string against a list of possible values, so I don't think there is a way for me to replace this with a "case" statement - and that may have the same limit. I looked and didn't see any mention of limit in the Propeller documentation. Where, if anywhere, does documentation of this limit (for "elseif" as well as "case") exist?

How can I get around this? Thanks.

Comments

  • Heater.Heater. Posts: 21,230
    edited 2013-12-24 23:38
    ags,
    I am comparing a string against a list of possible values
    How about:
    1) Define the strings you are testing against, the possible values, in a DAT section.
    2) Have a array of pointers to those strings, also in the DAT section.
    3) Create a loop in Spin that tests the input sting against the strings in DAT and exits when it finds a match. Producing a number indicating the match.
    4) Do a "case" on that loops output value. I forget what the limit on "case" is but I thought it was a lot more than 16.
    5) You can always split the value you are performing a case on into two parts and then use nested "case" to get what you want.

    Merry Christmas.
  • Mike GMike G Posts: 2,702
    edited 2013-12-25 02:39
    Depending on the implementation, place the conditional logic in a method. Replace the ELSEIF with IF and add a return within the IF code blocks.

    Although, I like the cleaner loop construct suggested by Heater.
Sign In or Register to comment.