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.

    1 answer 1

    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") } 
    • Thank! And that the recursion was not created? - Mothership
    • And, well, this is understandable, I just thought the recursion is going on in my main function. - Mothership