Without goroutine
Regular functions calls are executed sequentially. Each call can only start after all the previous calls have finished.
package main
import (
"fmt"
"time"
)
func count(n int, name string) {
for i := 0; i < n; i++ {
fmt.Printf("%s %d\n", name, i)
time.Sleep(1000)
}
}
func main() {
fmt.Println("Welcome")
count(3, "first")
count(3, "second")
count(3, "third")
count(3, "fourth")
fmt.Println("Done")
}
Welcome
first 0
first 1
first 2
second 0
second 1
second 2
third 0
third 1
third 2
fourth 0
fourth 1
fourth 2
Done