Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

a defer demo

  • Loading branch information...
commit 9558a3c7c104f94f9bd8c088e99238547a505ed1 1 parent bc5c873
@kicool authored
Showing with 39 additions and 0 deletions.
  1. +39 −0 defer/defer.go
View
39 defer/defer.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "fmt"
+ "log"
+)
+
+func bye(s string) {
+ log.Println("bye:", s)
+}
+
+func foo(i int) {
+ log.Println("IN Foo ", i)
+ defer bye(fmt.Sprintf("Defer3 Loop%d", i))
+ log.Println("OUT Foo ", i)
+
+}
+
+func main() {
+ log.Println("Start")
+
+ {
+ log.Println("IN1")
+ defer bye("Defer1")
+ log.Println("OUT1")
+ }
+
+ for i := 0; i < 3; i++ {
+ log.Println("IN2 ", i)
+ defer bye(fmt.Sprintf("Defer2 Loop%d", i))
+ log.Println("OUT2 ", i)
+ }
+
+ for i := 0; i < 3; i++ {
+ foo(i)
+ }
+
+ log.Println("End")
+}
Please sign in to comment.
Something went wrong with that request. Please try again.