Swift - Less Than or Equal To

Introduction

To determine whether a number is less than another number, use the less than ( < ) operator:

Demo

print(4 < 4)  //false
print(4 < 5)  //true
print(5 < 4)  //false

Result

You can also use the less than or equal to (>= ) operator:

Demo

print(8 <= 8) //true
print(9 <= 8) //false
print(7 <= 8) //true

Result

The < operator also work with strings:

Demo

print("abc" < "ABC") //false
print("123a" < "123b") //true

Result

The <= operator does not work with the String type.

Related Topic