O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Comparison operators

The comparison operator returns a Boolean true if the statement is true or a Boolean false if the statement is not true.

Here are some prototypes:

Equality:   
  varA == varB 
Not equal:   
  varA != varB 
Greater than:   
  varA > varB 
Less than:   
  varA < varB 
Greater than or equal to:   
  varA >= varB 
Less than or equal to: 
  varA <= varB 

Here are some examples:

2 == 1 //false, 2 does not equal 1 
2 != 1 //true, 2 does not equal 1 
2 > 1 //true, 2 is greater than 1 
2 < 1 //false, 2 is not less than 1 
2 >= 1 //true, 2 is greater or equal to 1 
2 <= 1 //false, 2 is not less or equal to 1 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required