Why is my foo () function not running?
package main import ( "fmt" ) func main() { fmt.Println("Ok") } func foo() { fmt.Println("ff") foo() } Only the main main () function, I seem to have initialized it.
Why is my foo () function not running?
package main import ( "fmt" ) func main() { fmt.Println("Ok") } func foo() { fmt.Println("ff") foo() } Only the main main () function, I seem to have initialized it.
For foo to execute, it must be called from main.
package main import ( "fmt" ) func main() { foo(); fmt.Println("Ok") } func foo() { fmt.Println("ff") foo() } but it’s better not to have a recursion there. foo calls itself.
And to avoid recursion, you need to remove the call from the foo function itself.
func foo() { fmt.Println("ff") } Source: https://ru.stackoverflow.com/questions/722202/
All Articles