Swift语言基础 - for循环与可选值
每天几分钟,轻松学苹果。
原文翻译
let individualScores = [75, 43, 103, 87, 12]
var teamScore = 0
for score in individualScores {
if score > 50 {
teamScore += 3
} else {
teamScore += 1
}
}
print(teamScore)
// Prints "11"
var optionalName: String? = "John Appleaseed"
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, \(name)"
}