Swift Double isLess()

The isLess() method checks if one number is less than another or not.


// check is 9 is less than 3 or not var result = 9.isLess(than: 10) print(result)
// Output: true

isLess() Syntax

The syntax of the isLess() method is:

num.isLess(than: otherNumber)

Here, num is a number.

isLess() Parameters

The isLess() method takes one parameter

  • otherNumber - the value to test

isLess() Return Values

The isLess() method returns boolean value

  • true - if num is less of otherNumber
  • false - if num is greater than otherNumber

Example 1: Swift Double isLess()

// check if 4 less than 2 or not
var result1 = 4.isLess(than: 2)
print(result1) // check if 2 is less than 4 or not
var result2 = 2.isLess(than: 4)
print(result2) // check if 210 is less than 110 or not
var result3 = 210.isLess(than: 110)



Here, since 4 is not less than 2, the isLess() method returns false. However, 2 is less than 4, the method returns true.

Lastly, since 210 is multiple of 110, the method returns false.

Example 2: Using if…else With isLess()

// check if 88 is less than 88.2 or not if 88.isLess(than: 88.2) {
print("The condition is true") } else { print("The condition is false") }


The condition is true

Here, since 88 is less than 88.2, the code inside the if block is executed.

Did you find this article helpful?