<div>It is a functional style, so typically you use return for continue and throws to accomplish break and return, e.g.:</div><div><br></div><div> // Continue</div><div> let a = [0, 1]</div><div><div> a.forEach { _ in return } // for _ in a { continue }</div><div><br></div><div> // Break and return</div><div> enum LoopControls<T>: Error {</div><div> case exitLoop // Break</div><div> case returnValue(T) // Return</div><div> }</div><div> do {</div><div> do {</div><div> try a.forEach { _ in throw LoopControls<Void>.exitLoop } // for _ in a { break }</div><div> } catch LoopControls<Void>.exitLoop {</div><div> // Process break if you need to</div><div> }</div><div> try a.forEach { _ in throw LoopControls<Double>.returnValue(42.0) } // for _ in a { return 42.0 }</div><div> } catch LoopControls<Double>.returnValue(let value) {</div><div> return value</div><div> }</div><div><br></div></div><div><br></div><div><br><div class="gmail_quote"><div>On Sun, 5 Feb 2017 at 2:32 pm, Rob Mayoff via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg">On Fri, Feb 3, 2017 at 7:15 PM, Howard Lovatt via swift-users <span class="gmail_msg"><<a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_msg">Why not add to the library:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg">extension Sequence {</div><div class="gmail_msg"> func forEach(_ eacher: (Iterator.Element) throws -> Void, elser: () throws -> Void) rethrows {</div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div></div><div class="gmail_msg"><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">This doesn't work with break or continue and changes the meaning of return.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">It would be nice for Swift to support Tcl-like exceptional return codes so we can build control flow functions that work with break, continue, and return properly.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><a href="http://www.tcl.tk/man/tcl/TclCmd/return.htm" class="gmail_msg" target="_blank">http://www.tcl.tk/man/tcl/TclCmd/return.htm</a><br class="gmail_msg"></div></div></div></div>
_______________________________________________<br class="gmail_msg">
swift-users mailing list<br class="gmail_msg">
<a href="mailto:swift-users@swift.org" class="gmail_msg" target="_blank">swift-users@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="gmail_msg">
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature">-- Howard.</div>