官术网_书友最值得收藏!

Relational operators

Relational operators compare two things (usually numbers) and always evaluate to a Boolean result. These operators are used to answer questions such as is 10 less than 20? Relational operators test for equality, inequality, and which of two arguments is less than or greater than the other.

The equality operator (==) checks whether the values of the two operands are equal or not. If they are equal, the operator evaluates to true, otherwise it evaluates to false. Here are examples:

x = 2 == 2 -- true
y = 2 == 3 -- false
z = "nine" == 9 -- false

The inequality operator (~=) checks whether the values of the two operands are equal or not. If they are NOT equal, the operator evaluates to true, otherwise it evaluates to false. Here is an example:

x = 2 ~= 2 -- false
y = 2 ~= 3 -- true
z = "nine" ~= 9 -- true

The greater than operator (>) checks whether the first operand is greater than the second operand. If it is, the operator evaluates to true, otherwise to false. Here is an example:

x = 4 > 5 -- false
y = 4 > 4 -- false
z = 4 > 3 -- true

The greater than or equal to operator (>=) checks whether the first operand is greater than or equal to the second operand. If it is, the operator evaluates to true, otherwise to false. Here is an example:

x = 4 >= 5 -- false
y = 4 >= 4 -- true
z = 4 >= 3 -- true

The less than operator (<) checks whether the first operand is less than the second operand. If it is, the operation evaluates to true, otherwise to false. Here is an example:

x = 3 < 2 -- false
y = 3 < 3 -- false
z = 3 < 4 -- true

The less than or equal to operator (<=) checks whether the first operand is less than or equal to the second operand. If it is, the operation evaluates to true, otherwise to false. Here is an example:

x = 3 <= 2 -- false
y = 3 <= 3 -- true
z = 3 <= 4 -- true
主站蜘蛛池模板: 巫溪县| 怀集县| 永新县| 乾安县| 荔波县| 蓝田县| 通渭县| 淳安县| 和田市| 偃师市| 大化| 许昌市| 宝坻区| 方正县| 内黄县| 内黄县| 武汉市| 长春市| 涿鹿县| 绿春县| 福建省| 怀来县| 平安县| 临沭县| 鄢陵县| 延吉市| 汤原县| 黔南| 新丰县| 泌阳县| 抚远县| 孝昌县| 甘德县| 吐鲁番市| 诏安县| 石嘴山市| 修文县| 清远市| 灵寿县| 达日县| 阜平县|