Chapter 18 : Comparison Operators

Topics Covered :

1. What are Comparison Operators
2. Equal to Operator
3. Not equal Operator
4. Less than Operator
5. Less than equal to Operator
6. Greater than Operator
7. Greater than or equal to Operator
8. Examples

# Comparison Operators

We can compare values of two operants (variables) using Comparison operators.

When you compare values using these operators the result is a Boolean value i.e true or false.

== : Equal to

!= : Not equal

< : Less than

<= : Less than equal to

> : Greater than

>= : Greater than or equal to

#### Example :

``````
//
//  main.swift
//  Swift Tutorials 2014-15
//  Comparison Operator in Swift
//
//  Created by Code2care on 16/09/14.
//

var a = 2
var b = 2
var c = 10

//Equal to
println("1. a == b : \(a == b)")
println("2. a == c : \(a == c)")

//Less-than
println("3. a < c : \(a < c)")
println("4. c < a : \(c < a)")

//Greater-than
println("5. a > c : \(a > c)")
println("6. c > a : \(c > a)")

// Less-than Equal
println("7. a <= c : \(a <= c)")
println("8. c <= a : \(c <= a)")

//Greater-than Equal
println("9. a >= c : \(a >= c)")
println("10. c >= a : \(c >= a)")

//Not Equal
println("11. a != c : \(a != c)")

```
```
Output :

1. a == b : true
2. a == c : false
3. a < c : true
4. c < a : false
5. a > c : false
6. c > a : true
7. a <= c : true
8. c <= a : false
9. a >= c : false
10. c >= a : true
11. a != c : true
Program ended with exit code: 0