📘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.
replit ( 👉 see: for...in vs. forEach )
⛔ 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
Was this helpful?