Problem Statement
When is the `defer` block executed in Swift?
Explanation
A `defer` statement schedules code to run when exiting the current lexical scope, whether via return, error, or normal exit. This ensures cleanup tasks such as closing files, releasing locks and cleaning up state run reliably in Swift.