InvaderZim
Senior Member
If statements don't behave quite like I'd expect in the simulator; is this a feature or a bug? Or a stupid user error?
In the following code, 2 inputs are decoded into 1 of 4 states; if there is a problem with decoding, then '99' is returned. The simulator decodes a state, skips the other 'elseif' statements, but then executes the 'else' to return 99.
I would expect the 'else' to be skipped whenever an 'if' (or 'elseif') was executed.
In the following code, 2 inputs are decoded into 1 of 4 states; if there is a problem with decoding, then '99' is returned. The simulator decodes a state, skips the other 'elseif' statements, but then executes the 'else' to return 99.
I would expect the 'else' to be skipped whenever an 'if' (or 'elseif') was executed.
Code:
#picaxe 18x
symbol sel0=input0
symbol sel1=input1
main:
gosub subselect
goto main
subselect:
if sel1=0 and sel0=0 then 'if statement to determine state
b1=1
'goto subselect2
elseif sel1=0 and sel0=1 then
b1=2
'goto subselect2
elseif sel1=1 and sel0=0 then
b1=3
'goto subselect2
elseif sel1=1 and sel0=1 then
b1=4
'goto subselect2
else
b1=99 'should never display
endif
subselect2: 'if/elseif is broken? have to code it with gotos?
return