Trouble with If Statements

BlitzMax Forums/BlitzMax Programming/Trouble with If Statements

DirtBikeDude(Posted 2007) [#1]
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" ))



Jake L.(Posted 2007) [#2]
Last one. You even need no outer brackets in your statement.


tonyg(Posted 2007) [#3]
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.


Who was John Galt?(Posted 2007) [#4]
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.


FlameDuck(Posted 2007) [#5]
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.