A little doubt about go concurrency

package main

import "fmt"

func main() {
    go loop()
    go loop()
}

func loop() {
    for i := 0; i < 10; iPP {
        fmt.Println(i)
    }
}

this is my code, and the result is nothing; as far as I understand it, it should output 0-9

on both sides.
Go
Jul.12,2022

The principle of the

Go language is that when the main function finishes, all running collaborations are terminated! That is to say, the main program has already exited, and the two function after go have not been executed yet, so you can't see the print.
you can let the main program "sleep" for a while and then quit, and then see the results!

package main

import (
   "fmt"
   "time"
)


func main() {
   go loop()
   go loop()
   time.Sleep(500000)
}

func loop() {
    for i := 0; i<10; iPP {
        fmt.Println(i)
    }
}

at least let the main go routine block and don't quit

  

when the main thread ends, the whole program ends

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ebaf1f-2813.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ebaf1f-2813.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?