Looking for | and || examples


#1

I am looking for coding examples using | and || in webcore pistons.
I am trying to learn how to use these in webcore.
Thanks.


#2

I use it in a piston like this, nothing fancy. In this example, I’m looking at the possible ways the first word ‘all’ can come in.


#3

Here is another example. I set ‘someone home’ boolean to an initial value depending if we have guests staying over. Then I check if my wife or myself are home with this expression:

Basically, || is a logical ‘or’ between logical values or expressions. Similarly, ‘&&’ is logical ‘and’.


#4

@eibyer, @guxdude Thanks for the examples guys. Correct me if I am wrong, but are those examples just a method to reduce coding? Generally speaking, logistically, nothing is gained over just writing out the code?


#5

Generally speaking, yes. There are some advantages at times to this syntax. For example, in the same example above but for another house with more residents, I did this:

Much simpler than putting another if statement within the loop.


#6

:+1: