Trouble with If Statements
BlitzMax Forums/BlitzMax Programming/Trouble with If Statements
| ||
I have a complicated If Statement. I'm not sure how I need to organize it. The code reads if "Lnd" is true then checks if "Ste" matches. If Lnd = True And Ste = "Stand" Or Ste = "Walk" Or Ste = "Crouch" Or Ste = "Crawl" Does this code read If Lnd is True then read If Ste matches? Or does the code read If Lnd is True and Ste = "Stand" then check weather Ste Matches another string and ignore Lnd? If so is it possible to use parenthesis within if statements? If ( Lnd = True And ( Ste = "Stand" Or Ste = "Walk" Or Ste = "Crouch" Or Ste = "Crawl" )) |
| ||
Last one. You even need no outer brackets in your statement. |
| ||
Depending on the rest of the code you might want to consider a simple 'If lnd=true' and then select/case statements for Ste. Might not matter now but might help readability in a few weeks time. <edit> and use more meaningful variable names. I realise it's your code so you know what they mean but, once the code size increases, you'll need readbility more often. I am guessing this is some of terrain check and the type of state that can be used. If so using 'Land' (or even land_type) rather than 'lnd' will help. |
| ||
Also, I would generally use constants in preference to strings for state variables (dependent, obviously, on what you are trying to achieve). Comparisons should be faster. |
| ||
Comparisons should be faster. But no longer type safe. Of course it would be better with a proper type safe enum, but for now, strings are pretty good. |