defer
defer runs code when the scope ends, great for cleanup.
Example
func work() {
print("start")
defer { print("cleanup") }
print("end")
}
work()Exercise
Run at scope end.
{ cleanup() }Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.