This has come up before. I don't think so. You can't have multiple conditions in an IF statement as far as I know. Parallax gave an answer about a year or so ago when I inquired, and it has to do with how to generate a corresponding codeblock in assembly.
I have usually worked around it.
Something like
......
if X=1 then somesubroutine
if P=7 then somesubroutine
......
...
..
somesubroutine:
do the same stuff for x=1 and p=7 here
RETURN
Actually your answer has a potential subtle bug in it - If both conditions happen to be true at the same time, then "somesubroutine" will get executed twice. If you want to prevent this possibility and SX/B won't allow an OR, the better solution is something like this:
ConditionMet = 0
If X = 1 then ConditionMet = 1
If P = 7 then Condition Met = 1
If ConditionMet = 1 then Somesubroutine
By using a separate flag to see if either (or both) conditions are met, you can then check the flag and call the subroutine exactly once. This exactly meets the definition of the OR truth table which looks like this:
0 or 0 = 0
0 or 1 = 1
1 or 0 = 1
1 or 1 = 1
This technique can also be extended to have as many conditional checks as you like. You just have to make sure the flag is cleared before the first conditional check so it is in a known state. You definitely do not want to do this:
if X = 1 then ConditionMet = 1 else ConditionMet = 0
if P = 7 then ConditionMet = 1 else ConditionMet = 0
...or else you end up turning the flag off unless both "If/Then" checks are true, or if only the second condition is true. Not the same results at all.
Like Keith, you have a subtle bug in your answer. If you enter the "Do" with P =7 and X = anything other than 1, then the first conditional check will drop execution out of the loop and thus never get to the conditional check for P = 7 which is true. This means that you'll never execute when P = 7 unless X = 1, which is not an "OR", but an "AND". The flag solution I presented earlier doesn't suffer from this problem.
Hi,
I Like Bean's solution because it doesn't require any additional variables to accomplish the conditional statement.
On a slightly different note, Of the hundreds of bytes of ram available on the sx48, why does it keep telling me I am out of it when I am only trying to use 20 bytes?
Comments
I have usually worked around it.
Something like
should work.
Actually your answer has a potential subtle bug in it - If both conditions happen to be true at the same time, then "somesubroutine" will get executed twice. If you want to prevent this possibility and SX/B won't allow an OR, the better solution is something like this:
By using a separate flag to see if either (or both) conditions are met, you can then check the flag and call the subroutine exactly once. This exactly meets the definition of the OR truth table which looks like this:
This technique can also be extended to have as many conditional checks as you like. You just have to make sure the flag is cleared before the first conditional check so it is in a known state. You definitely do not want to do this:
...or else you end up turning the flag off unless both "If/Then" checks are true, or if only the second condition is true. Not the same results at all.
Thanks, PeterM
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
Post Edited (Bean (Hitt Consulting)) : 11/21/2006 1:34:15 PM GMT
Like Keith, you have a subtle bug in your answer. If you enter the "Do" with P =7 and X = anything other than 1, then the first conditional check will drop execution out of the loop and thus never get to the conditional check for P = 7 which is true. This means that you'll never execute when P = 7 unless X = 1, which is not an "OR", but an "AND". The flag solution I presented earlier doesn't suffer from this problem.
Thanks, PeterM
Thanks for the catch Peter,
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·
I Like Bean's solution because it doesn't require any additional variables to accomplish the conditional statement.
On a slightly different note, Of the hundreds of bytes of ram available on the sx48, why does it keep telling me I am out of it when I am only trying to use 20 bytes?
Thad
Most of the RAM is available only for arrays.
In most cases you can use an array element instead of a simple byte variable.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·