Last active
October 2, 2016 03:33
-
-
Save zach-snell/940c1f0f03addcdfd6a5fc9eb073171f to your computer and use it in GitHub Desktop.
Swift 3 Bottom Up: Ep3 - Control Flow and Optionals https://www.youtube.com/watch?v=Fwdu_RRqejk
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
// MARK: Control Flow | |
// MARK: if / else if / else | |
var numberTest = 3 | |
if numberTest < 1 { | |
print ("true") | |
} else if numberTest == 2 { | |
print ("equals two") | |
} else { | |
print ("Number is greater than 1 and does not equal two") | |
} | |
// MARK: while / repeat-while | |
var count = 0 | |
while count != 10 { | |
print(count) | |
count += 1 | |
} | |
count = 11 | |
repeat { | |
print (count) | |
} while count != 11 | |
// MARK: for loops | |
for i in 0...10 { | |
print(i) | |
} | |
var array = ["1":"cat", "2":"dog", "3":"bear"] | |
for (key, animal) in array { | |
print (key) | |
} | |
// MARK: switch | |
switch "cat" { | |
case "bear", "cat": | |
print ("bear") | |
case "dog": | |
break | |
default: | |
print("default hit") | |
break | |
} | |
// MARK: Optionals | |
var testValue: Int? | |
testValue = 1 | |
if testValue != nil { | |
print(testValue!) | |
} | |
// MARK: Optional Control Flow | |
if let unwrappedValue = testValue { | |
print(unwrappedValue) | |
} else { | |
} | |
// guard let unwrappedIntValue = testValue else { return -1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment