Logical Operator

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Logical Operators

Introduction

A logical operator is one used to perform a comparison between two values and produce a result of true or false (there is no middle result: something is not half true or half false or "Don't Know"; either it is true or it is false).

Equality =

The equality operator is used to compare two values for similarity. The syntax of this operation is:

Value1 = Value2

If Value1 and Value2 hold the same value, then the comparison produces a TRUE result. If they hold different values, the comparison renders a FALSE value:

Once the comparison has been performed, it processes a Boolean value you can use as you see fit.

Inequality <>

To find out if two values are different, you can use the inequality operator which is represented by <>. Its syntax is:

Value1 <> Value2

This comparison is performed between Value1 and Value2. If they hold different values, then the comparison produces a TRUE result. If they hold the same value, the comparison produces FALSE

The equality (=) and the inequality (<>) operators are opposite each other.

Less Than <

The "Less Than" operator uses the following syntax:

Value1 < Value2

If Value1 holds a value that is lower than that of Value2, the comparison produces TRUE. If Value1 holds a value that is greater than or similar to that of Value2, the comparison renders FALSE

Less Than Or Equal <=

When comparing two values, you may want to know whether two fields hold the same value or if one is lower than the other. This comparison can be performed with the "Less Than Or Equal to" operator. It is represented by <=. Its syntax is:

Value1 <= Value2

If both operands (Value1 and Value2) hold the same value, then the comparison produces a TRUE result. If Value1 holds a value that is lower than that of Value2, the comparison still produces a TRUE result. By contrast, if the value of Value1 is higher than that of Value2, the comparison renders a FALSE result

Note that the > and the <= operators are opposite each other.

Greater Than >

If you have two values and want to find out whether they hold similar values or the first is greater than the second, you can use the >= operator whose syntax is:

Value1 >= Value2

If both Value1 and Value2 hold the same value, then the comparison renders a TRUE result. Similarly, if the left operand, Value1, holds a value greater than that of the right operand, Value2, the comparison still produces TRUE. If the value of Value1 is less than the value of Value2, the comparison produces a FALSE result

Therefore, < and >= are opposite.