๐Ÿ“˜return

Swift โŸฉ flow control โŸฉ control transfer โŸฉ return

cannot use return in the body of a for...in loop, except that the loop is inside a function.

โ›” error: return invalid outside of a func.

for n in 1...10 {
    if n == 3 { return }    // โ›” error
    //          ^^^^^^
    // โ›” error: return invalid outside of a func
}

Last updated