//ex1
for i in 0..<10 {
print(i)
} //0 1 2 3 4 5 6 7 8 9
//ex2
for item in [1,2,3,4,5] {
print(item)
} // 1 2 3 4 5
for (kor,eng) in dic1 {
print("key: \(kor) value: \(eng))"
for ch in str {
print(ch)
}
while i < 10 {
i += 1
}
var j = 0
repeat {
j += 1
print(j)
if j > 10 {
break
}
} while true
if let val = someFunc() {
print("\(val")
}
if #available(iOS 10, macOS 10.12.*) {
//iOS 10 이상, macOS 10.12 이상
}
Early Exit 용으로 사용.
guard [조건] else {} 구조로 사용합니다
var point = (4,2)
switch point {
case (4,let y) :
print(y) //2
case (let x, 2) :
print(x) //4
}
var point = (-1,-3)
switch point {
case let (x,y) where x>0 && y>0 :
print("1사분면")
case let (x,y) where x<0 && y>0 :
print("2사분면")
case let (x,y) where x<0 && y<0 :
print("3사분면")
case let (x,y) where x>0 && y<0 :
print("4사분면")
default : print("error")
}