PDA

View Full Version : Logical AND/OR/ Sequencing question



CuriousOne
- 2nd February 2021, 07:51
Hello.

Say here is a logical structure like this

IF A=1 AND B<6 OR A=2 THEN

The first part is clear, if a=1 and b is less than 6, then do something
but what about OR?
when I add that OR A=2 this means B still should be less than 6, or that part is ignored and only A=2 is checked?

HenrikOlsson
- 2nd February 2021, 08:21
AND, OR, XOR, ANDNOT, ORNOT, XORNOT all have the same precedence and so are evaluated from left to right. But, as the manual says:

Left-to-right is, in our opinion, unacceptable as a method of specifying the order of
evaluation. USE PARENTHESES to avoid ambiguity!

IF (A=1 AND B<6) OR (A=2) THEN makes it much clearer.

aerostar
- 2nd February 2021, 09:15
OT

Have you got your HTC dot matrix ? on your other posting http://www.picbasic.co.uk/forum/showthread.php?t=24178&p=146445#post146445

CuriousOne
- 2nd February 2021, 14:37
Nope, it is still on the way, will get it in week or so.

CuriousOne
- 2nd February 2021, 14:40
So my question will be split into things like

IF A=1 AND B<6

OR B<6 AND A=2

I want to make it such way, than if A=2, then it would not care about whenever B is less than 6 or not.

HenrikOlsson
- 2nd February 2021, 16:13
Have you TRIED it? Sometimes simply trying a few things out on your own gives you the answer much faster than asking here.


IF (A=1 AND B<6) OR (A=2) THEN
LED = 1
ENDIF

Whenever A = 2 LED will turn on.
If A = 1 then B must also be <6 for LED to turn on.

Ugly and verbose but likely smaller:

IF A = 2 THEN LED = 1
IF (A = 1) AND (B < 6) THEN LED = 1

/Henrik.

mpgmike
- 2nd February 2021, 16:30
Also, when using IF statements, it will probably take fewer lines of ASM code to execute if you put the clause most likely to give you a "yes", or the easiest to check first. IF (A = 2)... is the easiest to check so I'd put it first.

CuriousOne
- 3rd February 2021, 21:33
Well as I've said previously, sometimes I have no access to machine where PBP is installed. I tried to get a student license for my laptop, but it never works.
So sometimes, I write code on the road, in the notepad, which obviously, can't run PBP, so this is why I'm asking here.

HenrikOlsson
- 4th February 2021, 10:55
The gold and silver editions allows you to install and activate PBP on up to 3 machines, do you have that many and still need that extra laptop?

peterdeco1
- 4th February 2021, 18:51
Why not simply:

IF (A=2) THEN
IF (A=1) AND (B<6) THEN
IF (B<6) AND (A=2) THEN

CuriousOne
- 4th February 2021, 18:56
It is not my computer where PBP is installed, it belongs to company, so have no idea where any other remaining copies are installed or whatsoever. Regarding my laptop, it is not actually a laptop, but a Surface Pro 5, a tablet which works as a nice laptop, is super lightweight and portable. I was thinking about getting the silver version, but as I've stated in feature requests, I'd like to have say some "core package" for some relatively low price, say $29.99 and ability to add extra MCU support on paid basis - I will never use 99% of currently supported MCUs, so paying for thing that you're not going to use....