Related Articles
Loop Control Statements in Go Language
• Last Updated : 19 Nov, 2019

Loop control statements in the Go language are used to change the execution of the program. When the execution of the given loop left its scope, then the objects that are created within the scope are also demolished. The Go language supports 3 types of loop control statements:

1. Break
2. Goto
3. Continue

#### Break Statement

The break statement is used to terminate the loop or statement in which it presents. After that, the control will pass to the statements that present after the break statement, if available. If the break statement present in the nested loop, then it terminates only those loops which contains break statement.

Flow Chart: Example:

 `// Go program to illustrate ``// the use of break statement``package main`` ` `import ``"fmt"`` ` `// Main function``func main() {``   ``for` `i:=0; i<5; i++{``        ` `   ``fmt.Println(i)``    ` `   ``// For loop breaks when the value of i = 3``   ``if` `i == 3{``         ``break``;``  ``}``   ``}`` ` `    ` `}`

Output:

```0
1
2
3
```

#### Goto Statement

This statement is used to transfer control to the labeled statement in the program. The label is the valid identifier and placed just before the statement from where the control is transferred. Generally, goto statement is not used by the programmers because it is difficult to trace the control flow of the program.

Flow Chart: Example:

 `// Go program to illustrate ``// the use of goto statement``package main`` ` `import ``"fmt"`` ` `func main() {``   ``var x ``int` `= 0``    ` `   ``// for loop work as a while loop``  ``Lable1: ``for` `x < 8 {``      ``if` `x == 5 {``          ` `         ``// using goto statement``         ``x = x + 1;``         ``goto` `Lable1``      ``}``      ``fmt.Printf(``"value is: %d\n"``, x);``      ``x++;     ``   ``}  ``}`

Output:

```value is: 0
value is: 1
value is: 2
value is: 3
value is: 4
value is: 6
value is: 7
```

#### Continue Statement

This statement is used to skip over the execution part of the loop on a certain condition. After that, it transfers the control to the beginning of the loop. Basically, it skips its following statements and continues with the next iteration of the loop.

Flow Chart: Example:

 `// Go program to illustrate ``// the use of continue statement``package main`` ` `import ``"fmt"`` ` `func main() {``   ``var x ``int` `= 0``    ` `   ``// for loop work as a while loop``   ``for` `x < 8 {``      ``if` `x == 5 {``          ` `         ``// skip two iterations``         ``x = x + 2;``         ``continue``;``      ``}``      ``fmt.Printf(``"value is: %d\n"``, x);``      ``x++;     ``   ``}  ``}`

Output:

```value is: 0
value is: 1
value is: 2
value is: 3
value is: 4
value is: 7
```
My Personal Notes arrow_drop_up
{"ft_lang_label":"__label__en","ft_lang_prob":0.7737768,"math_prob":0.86030453,"size":2235,"snap":"2021-21-2021-25","text_gpt3_token_len":587,"char_repetition_ratio":0.18108472,"word_repetition_ratio":0.29069766,"special_character_ratio":0.27695748,"punctuation_ratio":0.13186814,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96599793,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-11T00:54:28Z\",\"WARC-Record-ID\":\"<urn:uuid:77141dfe-b575-4f55-bb42-481c4724bbdd>\",\"Content-Length\":\"93617\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7c62a8ef-4ce4-4c87-8448-768dc391f5f3>\",\"WARC-Concurrent-To\":\"<urn:uuid:d7e49a96-9c4c-4f41-b553-b3660fe414d4>\",\"WARC-IP-Address\":\"23.217.129.104\",\"WARC-Target-URI\":\"https://www.geeksforgeeks.org/loop-control-statements-in-go-language/?ref=rp\",\"WARC-Payload-Digest\":\"sha1:P5LCJSCSGG55L2XJ2BF44BRWFS2WGVTQ\",\"WARC-Block-Digest\":\"sha1:6ORIRPSNNVPGNLN5FPTLBNEVXYWJZJMK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243991553.4_warc_CC-MAIN-20210510235021-20210511025021-00264.warc.gz\"}"}