if statments
in Propeller 1
Can anyone tell me if there are any limitations to how many if statements you can have or nested elseif's? I'm programing in C. thank you
Comments
However if your code is nested many levels deep and is wondering off to the right then it's a sign that you should rethink what you are doing. Your function is probably becoming too big and complex to reason about easily or test easily. If there is a problem with it it's probably too big to post here and ask people to look at.
Clearly you are having a problem in some code you are writing. What?
Usually I chose to use switch after 2-3 nested if's.
Spin has a fairly amount of nested if's possible, but there is a final number, I remember something like 32.
C, as far as I know has no limits there, maybe your compiler might have some.
Enjoy!
Mike
Normally the limit is the address space available to the compiler for holding its parse tree, ie gigabytes on a typical computer these days. You will find the compile-time will become unusable first (unless you switch off optimizations).
For a particular code generator there may be limits due to the binary object format itself.
In general a good compiler has no limits other than resource limits, limits are a hardware thing really, not software.
case X+Y ' test expression
Using OTHER
The optional OTHER component of CASE is similar to the optional ELSE component of an IF structure.
from my code
OBJ ir : "IRC" '------------------------------ 'other stuff '------------------------------ PUB main ' Top of IR Code input loop: if IRcog > 0 ' if COG loaded okay? repeat If IRC_ret <> ir#NoNewCode ' we have a key code IRcode := IRC_ret ir.Start(IRCpin, @IRC_ret) ' set up for next code case IRcode ' Parse the key code ' control keys ir#power : ' <--- Note the colon! ' also note notation = this lable is a constant from ' an external object (irc.spin file in this case) LCD.CLS lcd.str(string("Power ")) if V_Pwr == 1 V_Pwr := 0 lcd.str(string("OFF ")) lcd.backlight(0) else V_Pwr := 1 lcd.str(string("ON ")) lcd.backlight(1) 'indentation shows end of IF V_Pwr ' numeric keys ' indentation shows end of CASE structure 'indentation shows end of IF IRC_code 'indentation shows end of REPEAT 'indentation shows end of IF IRcog
The indentation thing is the only thing I really don't care for in Spin.
Outside the editor it's so NON-obvious about what's going on, and
simply editing a line of code can radically alter the program structure.
But that's what we have, so enjoy it...