continue 语句

控制流 / 跳转语句

let numbers = [ 2, 3, 5, 7, 11, 13, 17, 19 ]
var str = ""
for i in 0 ..< numbers.count {
    if i % 2 == 1 {
        continue
    }
    str += (str == "" ? "" : "-") + "\(numbers[i])"
}
//str is "2-5-11-17"
print("str is \(str)")


The continue statement tells a loop to stop what it’s doing and start again at the beginning of the next iteration through the loop. It says “I am done with the current loop iteration” without leaving the loop altogether.