Relational and Logical Operators

Test conditions in For and While functions are Logical Expressions -- evaluate
to TRUE or FALSE.

Form logical expressions with the following operators


relational operators Type of Test

== or Equal[a,b] equal to
!= or Unequal[a,b] not equal to
> greater than
> = greater than or equal to
< less than
< = less than or equal to

Logical (Boolean)
Operators Operation
! not (flips logic value)
&& and (True if all exprs True)

|| or (True if at least one is True)
Xor[expr1, expr2, . . . exclusive or (True if only one
expr True)
=== or SameQ[a,b] equivalence (True if all exprs have same logic value)
=!= or UnsameQ[a,b] nonequivalence (True if exprs have opposite logic values)

Simple Logical Expressions

- formed with relational operators.

3 > 5

3 <= 5

4 + 2 == 5+1

w = 4; b = 5; w != b

4 < 7 <= 12

2 != 4 !=2