<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">The manual says this:<div class=""><br class=""></div><div class=""><a href="https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html" class="">https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html</a></div><div class=""><br class=""></div><div class=""><i class="">A defer statement is used for executing code just before transferring program control outside of the scope that the defer statement appears in.</i></div><div class=""><br class=""></div><div class="">The scope of a for loop ends when the loop ends.</div><div class=""><br class=""><div class="">Regards,<br class="">Rien<br class=""><br class="">Site: <a href="http://balancingrock.nl" class="">http://balancingrock.nl</a><br class="">Blog: <a href="http://swiftrien.blogspot.com" class="">http://swiftrien.blogspot.com</a><br class="">Github: <a href="http://github.com/Swiftrien" class="">http://github.com/Swiftrien</a><br class="">Project: <a href="http://swiftfire.nl" class="">http://swiftfire.nl</a><br class=""><br class=""><br class=""><br class=""></div><br class=""><blockquote type="cite" class="">On 10 Nov 2016, at 08:32, Andrea VEH via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class=""><br class="">Hello,<br class=""> From The Swift Programming Language, I learn the defer statements execute in the reverse order that they appear in the program. And when there are two or more defer statements in a loop(e.g. a for loop), defer statements execute still in the reverse order that they appear, but in the loop order that the loop statement executes. Code snippet is here(<a href="https://swiftlang.ng.bluemix.net/#/repl/582421bfdee52b5745935771" class="">https://swiftlang.ng.bluemix.net/#/repl/582421bfdee52b5745935771</a>).<br class=""> Early I saw this thread(https://twitter.com/lexrus/status/796370747849441280) from Twitter, I am curious about defer statement's execute order. Can you tell more details about it?<br class=""><br class="">Best regards,<br class="">_______________________________________________<br class="">swift-users mailing list<br class="">swift-users@swift.org<br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></blockquote><br class=""></div></body></html>