Arduino> Structure> Comparison Operators>
!=
[Comparison Operators]
Description
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the two operands are not equal. Please note that you may compare variables of different data types, but that could generate unpredictable results, it is therefore recommended to compare variables of the same data type including the signed/unsigned type.
Syntax
x != y; // is false if x is equal to y and it is true if x is not equal to y
Parameters
x
: variable. Allowed data types: int, float, double, byte, short, long.y
: variable or constant. Allowed data types: int, float, double, byte, short, long.Example Code
if (x != y) { // tests if x is not equal to y
// do something only if the comparison result is true
}
-------------------------------------------------------------------<
[Comparison Operators]
Description
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the operand on the left is less (smaller) than the operand on the right. Please note that you may compare variables of different data types, but that could generate unpredictable results, it is therefore recommended to compare variables of the same data type including the signed/unsigned type.
Syntax
x < y; // is true if x is smaller than y and it is false if x is equal or bigger than y
Parameters
x
: variable. Allowed data types: int, float, double, byte, short, long.y
: variable or constant. Allowed data types: int, float, double, byte, short, long.Example Code
if (x < y) { // tests if x is less (smaller) than y
// do something only if the comparison result is true
}
Notes and Warnings
Negative numbers are less than positive numbers.
-------------------------------------------------------------------<=
[Comparison Operators]
Description
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the operand on the left is less (smaller) than or equal to the operand on the right. Please note that you may compare variables of different data types, but that could generate unpredictable results, it is therefore recommended to compare variables of the same data type including the signed/unsigned type.
Syntax
x <= y; // is true if x is smaller than or equal to y and it is false if x is greater than y
Parameters
x
: variable. Allowed data types: int, float, double, byte, short, long.y
: variable or constant. Allowed data types: int, float, double, byte, short, long.Example Code
if (x <= y) { // tests if x is less (smaller) than or equal to y
// do something only if the comparison result is true
}
Notes and Warnings
Negative numbers are less than positive numbers.
-------------------------------------------------------------------==
[Comparison Operators]
Description
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the two operands are equal. Please note that you may compare variables of different data types, but that could generate unpredictable results, it is therefore recommended to compare variables of the same data type including the signed/unsigned type.
Syntax
x == y; // is true if x is equal to y and it is false if x is not equal to y
Parameters
x
: variable. Allowed data types: int, float, double, byte, short, long.y
: variable or constant. Allowed data types: int, float, double, byte, short, long.Example Code
if (x == y) { // tests if x is equal to y
// do something only if the comparison result is true
}
------------------------------------------------------------------->
[Comparison Operators]
Description
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the operand on the left is greater (bigger) than the operand on the right. Please note that you may compare variables of different data types, but that could generate unpredictable results, it is therefore recommended to compare variables of the same data type including the signed/unsigned type.
Syntax
x > y; // is true if x is bigger than y and it is false if x is equal or smaller than y
Parameters
x
: variable. Allowed data types: int, float, double, byte, short, long.y
: variable or constant. Allowed data types: int, float, double, byte, short, long.Example Code
if (x > y) { // tests if x is greater (bigger) than y
// do something only if the comparison result is true
}
Notes and Warnings
Positive numbers are greater than negative numbers.
------------------------------------------------------------------->=
[Comparison Operators]
Description
Compares the variable on the left with the value or variable on the right of the operator. Returns true when the operand on the left is greater (bigger) than or equal to the operand on the right. Please note that you may compare variables of different data types, but that could generate unpredictable results, it is therefore recommended to compare variables of the same data type including the signed/unsigned type.
Syntax
x >= y; // is true if x is bigger than or equal to y and it is false if x is smaller than y
Parameters
x
: variable. Allowed data types: int, float, double, byte, short, long.y
: variable or constant. Allowed data types: int, float, double, byte, short, long.Example Code
if (x >= y) { // tests if x is greater (bigger) than or equal to y
// do something only if the comparison result is true
}
Notes and Warnings
Positive numbers are greater than negative numbers.
-------------------------------------------------------------------
Post a Comment
Hi Users, if you have any queries then please let me know.