Home » Swift Comparison Operators

Swift Comparison Operators

by Online Tutorials Library

Comparison Operators

Swift 4 supports all standard comparison operators of C language.

  • Equal to (a == b)
  • Not equal to (a != b)
  • Greater than (a > b)
  • Less than (a < b)
  • Greater than or equal to (a >= b)
  • Less than or equal to (a <= b)

Note: Swift 4 also provides two identity operators (=== and !==), which is used to test whether both object references refer to the same object instance.

Every comparison operator returns a Bool value to specify whether the statement is true or not.

Comparison operators are used in conditional statement as if statement.

Example 1

Output:

hello, world  

Example 2

Output:

I am sorry. I don't recognize you  

You may also like