# Operators in Swift (AND, OR, or NOT.)

Operators in Swift, In computer programming, operators are constructs defined within programming languages that behave generally like functions, but which differ syntactically or semantically. Common simple examples include arithmetic, comparison, and logical operations.

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

• Arithmetic operators
• Assignment Operators
• Comparison Operators
• Logical Operators
• Bitwise Operators
• Misc Operators

Conditionals in Swift ( If, Else If, Else )

## Arithmetic Operators

Arithmetic operators are used to performing mathematical operations like addition, subtraction, multiplication, etc.

``````#Example

var a = 7
var b = 2

print (a + b)

// subtraction
print (a - b)

// multiplication
print (a * b)  ``````

## Assignment Operators

Assignment operators are used to assign values to variables.

``````#Example

// assign 10 to a
var a = 10

// assign 5 to b
var b = 5

// assign the sum of a and b to a
a += b      // a = a + b

print(a)
``````

## Comparison Operators

Comparison operators compare two values/variables and return a boolean result: true or false.

``````#Example

var a = 5, b = 2

// equal to operator
print(a == b)

// not equal to operator
print(a != b)

// greater than operator
print(a > b)

// less than operator
print(a < b)

// greater than or equal to operator
print(a >= b)

// less than or equal to operator
print(a <= b)``````

## Logical Operators

Logical operators are used to check whether an expression is true or false. They are used in decision-making.

``````// logical AND
print(true && true)      // true
print(true && false)     // false

// logical OR
print(true || false)      // true

// logical NOT
print(!true)                  // false``````

## Bitwise Operators

In Swift, bitwise operators are used to performing operations on individual bits.

## Misc Operators

Here’s a list of other operators available in Swift.

Happy Swift Coding ðŸ™‚

### Discover more from mycodetips

Subscribe to get the latest posts sent to your email.

## Discover more from mycodetips

Subscribe now to keep reading and get access to the full archive.