Languages Focus Logical operators perform conditional and , or , and not operations. Some languages support both binary logical operators that link two and unary logical operators negate (make opposite) the truth value of its argument. Finally, some languages short circuit logic. For example, with this or that , if this is an expression returning true, then that is never executed.
Access VBA:
and, or, not
Same as VB. Access VBA logical operators:
and
and, as in this and that
or
or, as in this or that
Not
Not, as in Not This
Access VBA never short circuits. Given the expression this or that as well as this and that , if this evaluates to false, then that is still executed.
Syntax Example: 'Given expressions a, b, c, and d: If Not (a and b) and (c or d) Then 'Do something. End If
Cross Reference Examples:
ASP Classic:
and, or, not
Same as VB. ASP Classic logical operators:
and
and, as in this and that
or
or, as in this or that
Not
Not, as in Not This
ASP Classic never short circuits. Given the expression this or that as well as this and that , if this evaluates to false, then that is still executed.
Syntax Example: 'Given expressions a, b, c, and d: If Not (a and b) and (c or d) Then 'Do something. End If
C#:
Same as C++ and Java. C# logical operators:
&
and, as in this and that
No Short Circuit
&&
and, as in this and that
short circuits
|
or, as in this or that
No Short Circuit
||
or, as in this or that
short circuits
!
Not, as in Not This
^
either or, as in this or that but not both
Syntax Example:
//Given expressions a, b, c, and d: if ! ((a && b) && (c || d)) { //Do something. }
C++:
C++ logical operators:
&&
and, as in this and that
||
or, as in this or that
!
Not, as in Not This
^
either or, as in this or that but not both
Syntax Example:
//Given expressions a, b, c, and d: if ! ((a && b) && (c || d)) { //Do something. }
C++/CLI:
Same as C++ and Java. C# logical operators:
&
and, as in this and that
No Short Circuit
&&
and, as in this and that
short circuits
|
or, as in this or that
No Short Circuit
||
or, as in this or that
short circuits
!
Not, as in Not This
^
either or, as in this or that but not both
Syntax Example:
//Given expressions a, b, c, and d: if ! ((a && b) && (c || d)) { //Do something. }
Corel Paradox:
ObjectPAL logical operators:
and
and, as in this and that
or
or, as in this or that
Not
Not, as in Not This
Like VBA, ObjectPAL never short circuits. Given the expression this or that as well as this and that , if this evaluates to false, then that is still executed.
Syntax Example: ;Given expressions a, b, c, and d: if Not (a and b) and (c or d) then ;Do something . endIf
Delphi:
Delphi logical operators:
and
and, as in this and that
or
or, as in this or that
not
Not, as in Not This
xor
either or, as in this or that but not both
The Delphi compiler default is to short circuit multi argument boolean expressions when the result is known before the evaluation completes. To disable short circuiting, use the {$B+} compiler directive. To reset it back to the compiler default of short circuting, use the {$B-} compiler directive.
Syntax Example: //Given expressions a, b, c, and d: if Not (a and b) and (c or d) then //Do something.
Delphi Prism:
Prism logical operators:
and
and, as in this and that
or
or, as in this or that
not
Not, as in Not This
xor
either or, as in this or that but not both
Syntax Example:
//Given expressions a, b, c, and d: if Not (a and b) and (c or d) then //Do something.
Java:
Java logical operators:
&&
and, as in this and that
||
or, as in this or that
!
Not, as in Not This
&
boolean logical OR (not short circuited)
|
boolean logical OR (not short circuited)
?:
Ternary (short for if-then-else)
~
Unary bitwise complement
<<
Signed left shift
>>
Signed right shift
>>>
Unsigned right shift
^
Bitwise exclusiv OR
Syntax Example:
//Given expressions a, b, c, and d: if ! ((a && b) && (c || d)) { //Do something. }
JavaScript:
JavaScript logical operators:
&&
and, as in this and that
||
or, as in this or that
!
Not, as in Not This
JavaScript always short circuits. Given the expression this || that , if this evaluates to true, then that is never executed.
Syntax Example:
//Given expressions a, b, c, and d: if ! ((a && b) && (c || d)) { //Do something. }
Perl:
Perl logical operators:
&& or and
and, as in this and that
|| or or
or, as in this or that
!
Not, as in Not This
Syntax Example:
#Given expressions a, b, c, and d: if ! ((a && b) && (c || d)) { #Do something. }
PHP:
and, &&, or, ||, !, Xor
PHP logical operators:
and , &&
and, as in this and that
or , ||
or, as in this or that
!
Not, as in Not This
Xor
either or, as in this or that but not both
Syntax Example:
#Given expressions a, b, c, and d: if ! ((a && b) && (c || d)) { #Do something. };
VB Classic:
and, or, not
VB Classic logical operators:
and
and, as in this and that
or
or, as in this or that
Not
Not, as in Not This
VB Classic never short circuits. Given the expression this or that as well as this and that , if this evaluates to false, then that is still executed.
Syntax Example: 'Given expressions a, b, c, and d: If Not (a and b) and (c or d) Then 'Do something. End If
VB.Net:
VB.Net logical operators:
And
and, as in this and that
No Short Circuit
AndAlso
and, as in this and that
short circuits
Or
or, as in this or that
No Short Circuit
OrElse
or, as in this or that
short circuits
Not
Not, as in Not This
Xor
either or, as in this or that but not both
Syntax Example:
'Given expressions a, b, c, and d: If Not (a and b) and (c or d) Then 'Do something. End If