How to combine AND and OR operators? ...Continued

Hi - following up on a thread: How to combine AND and OR operators?

That thread clarified that Bubble expressions evaluate left to right. And that the expression (i’m paraphrasing to simplify the example)

‘If search1 is empty OR if search2 is empty AND if search3 is not empty’

would evaluate to

‘(If search1 is empty OR if search2 is empty) AND if search3 is not empty’

e.g.

Yes AND Bool(search 3 is not empty)

So far so good.

I’d like to know what happens with a 4th option.

So does

‘If A is empty OR if B is empty AND if C is not empty OR if D is empty’

evaluate as

‘(If A is empty OR if B is empty) AND (if C is not empty OR if D is empty)’

or

‘(If A is empty OR if B is empty) (AND Bool(if C is not empty)) OR (Bool)if D is empty))’

e.g. - if A, B, and D are empty (yes) but and C is not ‘not empty’ (no)

then does it evaluate as

(Yes) AND (YES)

or

(Yes) AND (No) OR (Yes)

Bonus: If the latter, does the final calculation resolve to a yes or no?

Thank you! Need some help here :slight_smile:

Best,

P

Hi @scriptschool,

Personally, I just avoid the whole mess and use the Toolbox plugin’s Expression element where you can perform parenthetical expressions. The plugin is free and a solid performer, and now that it has a server script action, it can be used on server workflows as well.

–Ken

1 Like

Thanks @mebeingken - appreciated!

Toolbox notwithstanding, I’d like to understand how the above expression resolves in Bubble.

Anyone?

Thank you!

P

OMG I completely bypassed that feature from that element. Thanks!

1 Like

It’s easier to figure out the result of chained Boolean comparisons (in Bubble) than you are making it.

Here’s the general form of a Boolean comparison:

1 B 2

Where 1 and 2 are Boolean expressions and B is a Boolean operator (AND or OR in Bubble).

Let’s say that the result of 1 B 2 is represented by “12” (meaning the result of the comparison of “1” and “2”).

Now let’s look at a chain of such comparisons:

1 B 2 B 3 B 4 B 5

We just evaluate them left to right, each evaluation collapses the leftmost comparison, so we start as above, but step by step we get:

12 B 3 B 4 B 5
123 B 4 B 5
1234 B 5
12345

So:

AB AND C OR D
ABC OR D
ABCD

5 Likes

So if I understand correctly, the parenthetical equivalent would be:

((((1 B 2) B 3) B 4) B 5)

That right? Seems to match my experience (although I haven’t yet constructed too elaborate an expression).

2 Likes

Hi, thank you all.

Super helpful.

@keith, regarding your answer, how do you know this? Did you experiment, read documentation somewhere, or is it supposition?

Not so much questioning the veracity of the answer, as much as wanting to know how we might determine answers to questions like these (eg ‘the inner workings of Bubble’) in future.

Thanks!
P

It’s simply that the order of evaluation is left to right, as documented. And I’ve written many, many complex Boolean expressions in Bubble! Can confirm it works this way. :+1:

2 Likes

Awesome - thank you!

Much appreciated.

P

This topic was automatically closed after 70 days. New replies are no longer allowed.