Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
287 B

  1. package main
  2. import "fmt"
  3. func main() {
  4. counter := 4
  5. x := decrement(counter)
  6. fmt.Println(x())
  7. fmt.Println(x())
  8. fmt.Println(x())
  9. fmt.Println(x())
  10. fmt.Println("counter:", counter)
  11. }
  12. func decrement(i int) func() int {
  13. return func() int {
  14. i--
  15. return i
  16. }
  17. }