Last active
September 25, 2016 00:02
-
-
Save zach-snell/731a7a0b588a42c08553d29394475406 to your computer and use it in GitHub Desktop.
Swift 3 Bottom Up: Ep2 - Math and Boolean Operators (https://youtu.be/MANAkWA4_f0)
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 Darwin | |
// MARK: Operators | |
// = : Assignment | |
// + : Addition | |
// - : Subtraction | |
// * : Multiplication | |
// / : Division | |
// % : Modulus, Divison returning the remainder | |
// += : Addition followed by an assigment | |
// -= : Minus followed by assignment | |
// ^ : Bitwise XOR (NOT POWER FUNCTION) instead use Darwin and pow function | |
let one = 1 | |
var two = 2.0 | |
var three = 3.0 | |
three + two | |
three + 3 + two | |
three - two | |
three * two | |
three / two | |
15 % 5 // 15 / 5 = 3 (no remainder) | |
16 % 5 // 16 / 5 = 3 remainder 1 | |
var test = 1 | |
test += 3 | |
test | |
test -= 1 | |
test | |
pow(2.0, 4.0) | |
// MARK : Boolean logic comparisons | |
// == : Equals | |
// != : Not Equal | |
// < : Less than | |
// > : Greater than | |
// <= : Less than or equal to | |
// >= : Greater than or equal to | |
0 == 0 | |
0 == 1 | |
0 != 1 | |
0 != 0 | |
0 < 0 | |
0 > 0 | |
0 < 1 | |
0 > 1 | |
0 <= 0 | |
0 <= 1 | |
0 >= 0 | |
0 >= 1 | |
"test" == "test" | |
"test" == "nottest" | |
"test" == "Test".lowercased() | |
"Test".lowercased() | |
"test" != "nottest" | |
if 15 % 5 == 0 { | |
print("success") | |
} else { | |
print("fail") | |
} | |
"Hello " + "world" | |
// MARK: Boolean Logical Operators | |
// && : and of two booleans ( true && true == true true && false == false ) | |
// || : booean or of two boleans ( true || true == true true || false == true ) | |
// ! : boolean not of something : !true == false !false == true | |
true == true | |
(true && true) == true | |
(true && false) == true | |
((0 < 1) && (0 > -1) && (0 == 0)) == true | |
true == true | |
(true || true) == true | |
(true || false) == true | |
true || false | |
!(true && false) | |
!true | |
!false | |
if !(15 % 5 == 0) { | |
print ("failure") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment