{"id":830,"date":"2019-12-10T19:50:13","date_gmt":"2019-12-10T19:50:13","guid":{"rendered":"https:\/\/golangbyexamples.com\/?p=830"},"modified":"2019-12-10T19:50:22","modified_gmt":"2019-12-10T19:50:22","slug":"how-to-pause-a-go-program-until-enter-key-is-pressed","status":"publish","type":"post","link":"https:\/\/golangbyexamples.com\/how-to-pause-a-go-program-until-enter-key-is-pressed\/","title":{"rendered":"How to Pause a Go Program until enter key is pressed"},"content":{"rendered":"\n
Sometimes there is a need to pause a go program until a key is pressed. Eg. One would only want a go program to exit at the end only on the press of Enter<\/strong> key.<\/p>\n\n\n\n Below program will print the increasing and will stop as soon as you press the key is pressed. Try it out.<\/p>\n\n\n\n Sometimes there is a need to pause a go program until a key is pressed. Eg. One would only want a go program to exit at the end only on the press…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"class_list":["post-830","post","type-post","status-publish","format-standard","hentry","category-tech"],"yoast_head":"\npackage main\n\nimport (\n \"fmt\"\n \"time\"\n)\n\nfunc main() {\n go counter()\n fmt.Println(\"Press the Enter Key to stop anytime\")\n fmt.Scanln()\n}\n\nfunc counter() {\n i := 0\n for {\n fmt.Println(i)\n time.Sleep(time.Second * 1)\n i++\n }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"