@kjk1/

gobook defer basics 3

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6179153157695045","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgImZtdCIKCi8vIDpzaG93IHN0YXJ0CgpmdW5jIGxvZ051bShpIGludCkgewoJZm10LlByaW50ZigiTnVtICVkXG4iLCBpKQp9CgpmdW5jIG1haW4oKSB7CglpIDo9IDEKCWRlZmVyIGxvZ051bShpKSAvLyBkZWZlcnJlZCBmdW5jdGlvbiBjYWxsOiBsb2dOdW0oMSkKCWZtdC5QcmludGxuKCJGaXJzdCBtYWluIHN0YXRlbWVudCIpCglpKysKCWRlZmVyIGxvZ051bShpKSAgICAgLy8gZGVmZXJyZWQgZnVuY3Rpb24gY2FsbDogbG9nTnVtKDIpCglkZWZlciBsb2dOdW0oaSAqIGkpIC8vIGRlZmVycmVkIGZ1bmN0aW9uIGNhbGw6IGxvZ051bSg0KQp9CgovLyA6c2hvdyBlbmQ="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package main

import "fmt"

// :show start

func logNum(i int) {
	fmt.Printf("Num %d\n", i)
}

func main() {
	i := 1
	defer logNum(i) // deferred function call: logNum(1)
	fmt.Println("First main statement")
	i++
	defer logNum(i)     // deferred function call: logNum(2)
	defer logNum(i * i) // deferred function call: logNum(4)
}

// :show end