[swift-users] Details of defer statement in Swift
Rien at Balancingrock.nl
Thu Nov 10 01:45:20 CST 2016
The manual says this:
A defer statement is used for executing code just before transferring program control outside of the scope that the defer statement appears in.
The scope of a for loop ends when the loop ends.
> On 10 Nov 2016, at 08:32, Andrea VEH via swift-users <swift-users at swift.org> wrote:
> 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(https://swiftlang.ng.bluemix.net/#/repl/582421bfdee52b5745935771).
> 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?
> Best regards,
> swift-users mailing list
> swift-users at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users