let i: Int = 10 let d = 53.8 // doubleになる let s = "string" let flag = true // bool true/false var x = "five" x = String(5) print(x)
バックスラッシュはoption + ¥
// 数値 // + - * / % // print(10 / 3) // print(10.0 / 3) var y = 10 y *= 10 print("hello" + " world!") print("y is \(y - 5)")
&& || !
let score = 82 let result: String if score > 80 { result = "great" } else if score > 60{ result = "good" } else { result = "so so..." } print(result)
条件演算子
result = score > 80 ? "great" : "soso.." print(result)
case
let num = 4 switch num { case 0: print("zero") case 1, 2, 3: print("small") case 4..6: print("4/5/6") case 7..<9: print("7/8") case let n where n > 20: print("\(n) is huge!") default: print("n.a.") }