learning closure | IMPORTANT (revisit)

This commit is contained in:
2026-09-08 13:19:05 -04:00
parent c446285d63
commit 662e044c2c
2 changed files with 23 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
package main
import (
"fmt"
)
func fib() func() int {
a, b := 0, 1
return func() int {
a, b = b, a+b
return b
}
}
func main() {
f := fib()
for x := f(); x < 100; x = f() {
fmt.Println(x)
}
}