Go Languages break statement
Go language break statement to the following two aspects:
- For circulating a statement out of the loop and begins executing the statement after the loop.
- break switch (switch statement) out of action in the statement after the implementation of a case.
grammar
break syntax is as follows:
break;
break statement is a flow chart is as follows:
Examples
package main import "fmt" func main() { /* 定义局部变量 */ var a int = 10 /* for 循环 */ for a < 20 { fmt.Printf("a 的值为 : %d\n", a); a++; if a > 15 { /* 使用 break 语句跳出循环 */ break; } } }
The above examples Implementation of the results:
a 的值为 : 10 a 的值为 : 11 a 的值为 : 12 a 的值为 : 13 a 的值为 : 14 a 的值为 : 15