Created
September 19, 2022 14:07
-
-
Save AhmedMenaim/16c1bbf30918dcee713238aaae4bddaa to your computer and use it in GitHub Desktop.
Menaim Academy - Swift Course - Operators Part I
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// MARK: - Assignment Operator = | |
var a = 15 | |
var b = 5 | |
// MARK: - Arithmetic Operators + - * / | |
print(a+b) | |
print(a-b) | |
print(a*b) | |
print(a/b) | |
// MARK: - Remainder Operator % | |
let c = 4 // -> Int without .5756 | |
print(a/c) // -> 15 / 4 = 3 -> % = 15 - (3*4) = 15 - 12 = 3 | |
print(a%c) | |
let firstNumber = 5 | |
let secondNumber = 2 | |
print(firstNumber / secondNumber) // -> 5 / 2 = 2 -> % = 5 - (2 * 2) = 1 | |
print(firstNumber % secondNumber) | |
// MARK: - Unary Minus Operator | |
//a = -a // = -15 | |
//print(a) | |
//print(-a) // - * - = + | |
// MARK: - Unary Plus Operator | |
a = +a // - * + = - | |
// MARK: - Compound Assignment Operators | |
a = a + 5 // Add 5 on a and store it in a -> 20 | |
a += 5 // a -= 5 // 25 | |
a -= 5 | |
a += b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment