123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|568|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> If... And...And... Or... logic

Tue, 16 Oct 2007, 13:47
Forklift_Fred
OK, I'm sure there's a way of doing this but it's driving me crazy!

I need to check if either 2 conditions are both true or a third condition is true

So that's either condition 1 is true AND condition 2 is true, OR condition 3 is true.

I can right it as


But I either have to use a new function - hence DoStuff() - or put the code in twice. Neither are particularly neat and tidy.

I'm sure it can all be done in one hit a bit like

I didn't imagine it did I?

If it helps, all three conditions can be true but they don't have to be. Condition 3 can be true on its own but if condition 1 is true then condition 2 must be as well (and vise verse)

Does this even make sense ?

Another way of looking at it is checking if a variable is between two values (If x>0 And x<10), or if a flag is set.

-=-=-
Come rain or shine...
Tue, 16 Oct 2007, 13:54
JL235
Yes, are you referring to short circuiting? Where if I do:

Bar is only checked if foo fails. Otherwise if foo is true then there is no point in checking bar and bar is then skipped. Is this what your talking about?

Blitz Basic does not do short circuiting. I have encountered problems where my code does not work because I have expected to be able to use this. This is also strange because most languages do support short circuiting. Most languages also use correct boolean logic, again unlike Blitz Basic.

Short circuiting is very useful for stuff like:

Where I can check if a list both exists and is not empty. Without short circuiting the above code would not work, because if the list is null then I cannot call it's isEmpty() method.
Tue, 16 Oct 2007, 14:05
Forklift_Fred
Er... not sure. I don't think so.

My query looks a little like this at the moment

(which obviously doesn't work because it doesn't know how I want the And and Or to relate)

I need either the speed to be between -2 and 2 or for the flag 'spun' to be set to true.

The line I have could be read as speed less than 2 and either speed above -2 or spun. Which isn't right. I want to be able to check the speed as 1 condition without using the following.


Though thinking about it, that's only 1 extra line so I could use that I guess...

-=-=-
Come rain or shine...
Tue, 16 Oct 2007, 14:23
Forklift_Fred
Sorry, I forgot to say thank you for trying to help.

I've now implemented the last idea but it seems there is a problem elsewhere in my code so although it achieves the required logic, it still doesn't work!

-=-=-
Come rain or shine...
Tue, 16 Oct 2007, 15:02
Jayenkai
Your first example should work just fine.
If (A and B) or c then .. should work exactly as expected.
Only if you bracket them, though.
If A and B or C then.. will actually check
if A and (B or C), not the other way around.

-=-=-
''Load, Next List!''
Tue, 16 Oct 2007, 15:20
Forklift_Fred
He he he!

I now have it working! The problem was elsewhere, hidden away in a silly little flag set that didn't need to be there (it reset the speed)

Following your encouragement Jay, I tried all variations and discovered that although I had it working without brackets there was still a glitch:

A and B or C Worked but glitched at a secondary stage
A and (B or C) Was just bizarre!
(A and B) or C Works perfectly

So I'm not sure what the unbracketed version was checking and at this stage I don't care!

Thanks everyone, I can now focus on another hic-up that has just emerged... coding is fun!

-=-=-
Come rain or shine...