and / or

Jeremy Leach

Senior Member
Just want to check my understanding...

Suppose you have:
<code><pre><font size=2 face='Courier'>
If b0=1 OR b0=3 OR b0=7 AND b1=6 Then
&lt;Code&gt;
EndIf
</font></pre></code>

I think I'm right in saying the condition is processed left to right, so it progresses like this...

1. Evaluate b0=1 to True/False and store in current result.
2. Evaluate b0=3 to True/False and OR with current result to give new result.
3. Evaluate b0=7 to True/False and OR with current result to give new result.
4. Evaluate b1=6 to True/False and AND with current result to give new result.
 

hippy

Technical Support
Staff member
No <img src="sad.gif" width=15 height=15 align=middle>

It seems to parse from right to left, but I never got any detailed answer from Technical except the recommendation not to mix And and Or in a single expression ( I can't find the forum posting ).
 

sedeap

Senior Member
*****************
Probabily you MUST separate it with brackets

If b0=1 OR b0=3 OR b0=7 AND b1=6 Then
&lt;Code&gt;

So:
If (b0=1 OR b0=3 OR b0=7) AND b1=6 Then
&lt;Code&gt;

Or:
If b0=1 OR b0=3 OR (b0=7 AND b1=6) Then
&lt;Code&gt;

:eek:)
 

Jeremy Leach

Senior Member
Well, I want :
If (b0=1 OR b0=3 OR b0=7) AND b1=6 Then
&lt;Code&gt;

But brackets aren't supported, so if it is processed right to left then I'd need :


If b1=6 AND b0=1 OR b0=3 OR b0=7 Then
&lt;Code&gt;

Perhaps?

A good grasp of this would be really useful and avoid nesting IFs just because I don't understand !

Edited by - jeremy leach on 09/08/2007 20:24:38
 

hippy

Technical Support
Staff member
Found my original posting and Technical's answer - <A href='http://www.rev-ed.co.uk/picaxe/forum/Topic.asp?topic_id=7206&amp;forum_id=10&amp;Topic_Title=If%252DAnd%252DOr%252DThen%2B%252D%2Bbug%252Fanomaly&amp;forum_title=Software+Feedback' Target=_Blank>External Web Link</a>

As the simulators have been corrected to behave as a PICAXE does it should be possible to simulate the code and jiggle the conditional until it matches what you want ...<code><pre><font size=2 face='Courier'>For b0 = 0 To 8
For b1 = 5 To 7
If b0=1 OR b0=3 OR b0=7 AND b1=6 Then
SerTxd(#b0,&quot; &quot;,#b1,&quot; TRUE&quot;)
Else
SerTxd(#b0,&quot; &quot;,#b1,&quot; FALSE&quot;)
End If
Next
Next </font></pre></code> In your case my guess would be ...<code><pre><font size=2 face='Courier'>If b1=6 AND b0=1 OR b0=3 OR b0=7 Then </font></pre></code>
 
Top