Logical Operators
When working with comparative operators, it is incredibly useful to be able to quickly and concisely check the comparisons meet certain conditions.
Execution Order
Logical operators like and
and or
are evaluated after all other comparisons or expressions on either side of the operator are evaluated. This means that, in an expression such as 10 == 10 and true
, the comparison 10 == 10
is evaluated first, returning true
. Then, the logical and
operation is performed.
AND
A logical and statement will evaluate both of its operands, and if they are both true, then it will return true, otherwise it will return false. The way you write an and
operator in osl is simply a lowercase and
.
You can see the truth table below
A | B | A and B |
---|---|---|
true | true | true |
true | false | false |
false | true | false |
false | false | false |
OR
A logical or statement will evaluate both of its operands, and if either or both of them are true, then it will return true, otherwise it will return false. The way you write an or
operator in osl is simply a lowercase or
.
You can see the truth table below
A | B | A or B |
---|---|---|
true | true | true |
true | false | true |
false | true | true |
false | false | false |
NOR
A logical nor statement will evaluate both of its operands, and if neither of them are true, then it will return true, otherwise it will return false. The way you write a nor
operator in osl is simply a lowercase nor
.
You can see the truth table below
A | B | A nor B |
---|---|---|
true | true | false |
true | false | false |
false | true | false |
false | false | true |
XOR
A logical xor statement will evaluate both of its operands, and if both are true or both are false, then it will return false, otherwise it will return true. The way you write a xor
operator in osl is simply a lowercase xor
.
You can see the truth table below
A | B | A nor B |
---|---|---|
true | true | false |
true | false | true |
false | true | true |
false | false | false |
XNOR
A logical xnor statement will evaluate both of its operands, and if both of them are true or both of them are false, then it will return true, otherwise it will return false. The way you write a xnor
operator in osl is simply a lowercase xnor
.
You can see the truth table below
A | B | A nor B |
---|---|---|
true | true | true |
true | false | false |
false | true | false |
false | false | true |
NAND
A logical nand statement will evaluate both of its operands, and if both of them aren't true, then it will return true, otherwise it will return false. The way you write a nand
operator in osl is simply a lowercase nand
.
You can see the truth table below
A | B | A nor B |
---|---|---|
true | true | false |
true | false | true |
false | true | true |
false | false | true |
Last updated