var n = 0
while n < 3{
print(n)
n += 1
}
[/code]
repeat while
[code]
var n = 0
repeat {
print(n)
n += 1
} while n < 3
[/code]
for
[code]
for i in 0...5 {
print(i)
}
[/code]
for break
[code]
for i in 0...5 {
if i == 3 {
break
continue
}
print(i)
}
[/code]
optional
[code]
// let s: Optional<String> = nil
let s: String? = nil
// if s != nil{
// print(s!)
// }
// optional binding
if let value = s {
print(value)
}
配列
//var scores:[Int] = [50, 40, 30]
// var scores = [50, 30]
// print(scores[1])
// print(scores.count)
// print(scores.isEmpty)
var names = [String]()
names.append("John")
names.append("adam")
names += ["yokoi"]
for name in names {
print(name)
}
タプル
// var items = ("apple", 5)
// print(items.0)
// items.1 = 8
// print(items)
// let(product, amount) = items
// print(product)
// print(amount)
// let (product, _) = items
// print(product)
var items = (product: "apple", amount: 5)
print(items.product)