Solution Review: Multiplication Table
This lesson contains the solution review for the exercise on Multiplication Table.
We'll cover the following...
We'll cover the following...
Here is the code to the challenge in the previous lesson:
Go (1.6.2)
package mainimport ( "fmt""sync""time")func printTable(n int, wg *sync.WaitGroup) {for i := 1; i <= 12; i++ {fmt.Printf("%d x %d = %d\n", i, n, n*i)time.Sleep(50 * time.Millisecond)}wg.Done()}func main() {var wg sync.WaitGroupfor number := 2; number <= 12; number++ {wg.Add(1)go printTable(number,&wg)}wg.Wait()}
So we added a WaitGroup from the sync package on line 15 named wg. At every iteration in the for-loop in the main routine, we increment the counter of wg on line 18. In the next step on line 19, we execute the  ...