Thursday, January 09, 2020

Swift Operators - Basic Part 1

Assignment Operators

  • It initialize or updates the value of a variable with the value of b (a=b)
  • It also supports tuples ((x,y) = (1,2) x -1 and y-2)
  • If x= y {} this is invalid, reason it does not return anything, it just assigns. 

Arithmatic Operators

  • Addition (+)
  • Subtraction (-)
  • Multipication (*)
  • Divisions(/)

Reminder (Modulas) Operator (%) 

  • 7 % 3 = 1  (3*2)+1 = 7 
  • a % b means (b * multipier) + reminder = a 

Unary Minus and Unary Plus:

  •   - a or + a
     Example: a = 3, then -a = -3 and +a = -3
                    +a does not change anything

Compound Assignment opertors

  • It combines assignment operator with another operations.
          Example a += 2 => a = a+2

No comments:

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...