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) → bool

This operator-less-than operator of int relational less than operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredThe other number to compare against.


✐ Examples

1 Less than comparison

In this example,

  1. We create two integer variables num1 and num2 with values 5 and 10 respectively.
  2. We use the < operator to check if num1 is less than num2.
  3. 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,

  1. We create two integer variables num3 and num4 with values -3 and -8 respectively.
  2. We use the < operator to check if num3 is less than num4.
  3. 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,

  1. We create two integer variables num5 and num6 with values 15 and 7 respectively.
  2. We use the < operator to check if num5 is less than num6.
  3. 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.