Working with functions

What output will be produced when the following code snippet is executed?

func Sequence() func() int {
 i:= 0
 return func() int {
 i+=1
 return i 
 }
}

func main(){

 num := Sequence() 

 fmt.Println(num())
 fmt.Println(num())
 fmt.Println(num())
 
 num1 := Sequence() 

 fmt.Println(num1())
 fmt.Println(num1())
}
Options

1.1

2

3

1

2

2.0

1

2

0

1

3.1

2

3

4

5

4.0

1

2

3

4

Related Posts

Close Bitnami banner
Bitnami