{"id":1590,"date":"2020-03-08T12:23:14","date_gmt":"2020-03-08T12:23:14","guid":{"rendered":"https:\/\/golangbyexamples.com\/?p=1590"},"modified":"2020-03-08T12:23:22","modified_gmt":"2020-03-08T12:23:22","slug":"go-implement-while-loop","status":"publish","type":"post","link":"https:\/\/golangbyexamples.com\/go-implement-while-loop\/","title":{"rendered":"Implement while loop in Go (Golang)"},"content":{"rendered":"\n
Go doesn’t have the while<\/strong> keyword. Instead, it has the for<\/strong> keyword only. However for<\/strong> keyword can be used to simulate the functionality the same as while<\/strong>. <\/p>\n\n\n\n for<\/strong> loop in GO basically has three parts:<\/p>\n\n\n\n for<\/strong> loop can be implemented to behave the same as while<\/strong> if initialization_part<\/strong> and increment_part<\/strong> can be skipped. Here is an example:<\/p>\n\n\n\n Output:<\/strong><\/p>\n\n\n\n Go doesn’t have the while keyword. Instead, it has the for keyword only. However for keyword can be used to simulate the functionality the same as while. for loop in GO basically…<\/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":[4],"class_list":["post-1590","post","type-post","status-publish","format-standard","hentry","category-tech","tag-golang"],"yoast_head":"\nfor initialization_part; condition_part; increment_part {\n ...\n}<\/code><\/pre>\n\n\n\n
package main\n\nimport \"fmt\"\n\nfunc main() {\n i := 1\n for i <= 5 {\n fmt.Println(i)\n i++\n }\n}<\/code><\/pre>\n\n\n\n
1\n2\n3\n4\n5<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"