Sleeping in Golang
Sleeping in Go and how to pause execution and sleep for a number of seconds in Go (golang). We can use the time package from the standard library to sleep for a duration of time. You can use any duration of time, providing you use the constants provided. In our example below we sleep for two seconds, and to illustrate the point, we print out the time before and after we do this.
While True Loop in Go
While loops do not actually exist within Go (golang), by name, but the same functionality is achievable with a for loop. Which is great, why have a ‘while’ when the same can be done with ‘for’. Our example below shows how you get a Go program to print out a message every second to the screen. (You’ll have to exit to application to stop it, e.g. Ctrl+C)