swift 基本

var n = 0

while n < 3{
    print(n)
    n += 1
}
&#91;/code&#93;

repeat while
&#91;code&#93;
var n = 0

repeat {
    print(n)
    n += 1
} while n < 3
&#91;/code&#93;

for
&#91;code&#93;
for i in 0...5 {
    print(i)
}
&#91;/code&#93;

for break
&#91;code&#93;
for i in 0...5 {
    if i == 3 {
        break
        continue
    }
    print(i)
}
&#91;/code&#93;

optional
&#91;code&#93;
// 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)