IF statement with multiple conditions

JamesWhite

New Member
I was pulling my hair out on a program I am working on.
I have an
Code:
IF a=b and c=d and e=f and g=h then xxx
When it tests these conditions in simulation it jumps to xxx even when all of the tested variables are not equal.

Then I realized maybe it's the simulator that is wrong because the program seems to work on chip. I checked the revision history for PE6 and realized that I had 6.0.7.5 and that in 6.0.8.0 this bug was fixed. Woohoo! But sadly it was not so easy. I installed the new version and it appears that it is still not working. Attached you will find my full code. Thanks.

View attachment BoBJr_3.bas
 

hippy

Technical Support
Staff member
That would be correct and expected behaviour. Consider -

IF a = b AND c = d THEN xxx

You are only checking a=b and c=d, you are not checking a=c or similar. so a=1, b=1, c=2, d=2 will cause a jump to xxx.
 

JamesWhite

New Member
I'm not sure I follow you hippy.

Code:
Main:
Do
Let a=1:Let b=1:Let c=2:Let d=3:Let e=1:Let f=3:Let g=1:Let h=1
If a=b and c=d and e=f and g=h then stop
Loop

Stop:
End
Are you saying that expected behavior of this code would be to jump to stop after checking it?

In my previous comment I said "jumps to xxx even when all of the tested variables are not equal" this might be confusing but I meant only the variables that are actually tested in the IF statement... not for a=c condition or anything but a=b and c=d and e=f and g=h.

Funny thing is that a simplified version of my code simulates fine but the code I attached to the opening post will not simulate the IF statement in the same manner. I'm curious if it simulates for anyone else.
 

hippy

Technical Support
Staff member
In my testing the multiple conditional code appears to be working as expected.

Do you have any simplified code which demonstrates the problem you are seeing ? In your BoBJr_3.bas file the only multi-AND if statement I could spot was at line 217-219, which would seem to go to 'Finished:' regardless ...

Code:
if vLHip=vLHipGoal and vLFoot=vLFootGoal and vRFoot=vRFootGoal and vRHip=vRHipGoal then finished

finished:
 

JamesWhite

New Member
Dang it! I was attempting workarounds and must have deleted that bit before pasting to the forum. I originally had

Code:
doneyet:
pause vDelay1
if vLHip=vLHipGoal and vLFoot=vLFootGoal and vRFoot=vRFootGoal and vRHip=vRHipGoal then finished
[I]goto testLHip[/I]

finished:		      
return
Which would not simulate for me. Sorry for the inconvenience.

I'm at work currently but I'll copy my other code here when I return home this evening.

Thanks for the help hippy.
 

JamesWhite

New Member
Well, after testing this some more this evening, all is working fine. The best I can figure is that I should have rebooted after updating the PE to 6.0.8.0 because today it works as expected. Please accept my apologies for raising the issue without being thorough enough and feel free to delete this thread. Thanks for your help hippy, it is very much appreciated.
 
Top