Dart int operator-less-than
Syntax & Examples
int.operator-less-than operator
The `<` operator in Dart checks if the left operand is less than the right operand.
Syntax of int.operator-less-than
The syntax of int.operator-less-than operator is:
operator <(num other) → boolThis operator-less-than operator of int relational less than operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | The other number to compare against. |
✐ Examples
1 Less than comparison
In this example,
- We create two integer variables
num1andnum2with values 5 and 10 respectively. - We use the
<operator to check ifnum1is less thannum2. - We then print the result to standard output.
Dart Program
void main() {
int num1 = 5;
int num2 = 10;
bool result1 = num1 < num2;
print('$num1 is less than $num2: $result1');
}Output
5 is less than 10: true
2 Less than comparison
In this example,
- We create two integer variables
num3andnum4with values -3 and -8 respectively. - We use the
<operator to check ifnum3is less thannum4. - We then print the result to standard output.
Dart Program
void main() {
int num3 = -3;
int num4 = -8;
bool result2 = num3 < num4;
print('$num3 is less than $num4: $result2');
}Output
-3 is less than -8: false
3 Less than comparison
In this example,
- We create two integer variables
num5andnum6with values 15 and 7 respectively. - We use the
<operator to check ifnum5is less thannum6. - We then print the result to standard output.
Dart Program
void main() {
int num5 = 15;
int num6 = 7;
bool result3 = num5 < num6;
print('$num5 is less than $num6: $result3');
}Output
15 is less than 7: false
Summary
In this Dart tutorial, we learned about operator-less-than operator of int: the syntax and few working examples with output and detailed explanation for each example.