Goto statement
The goto statement in the Go programming language provides the ability to jump from jump to tag declaration unconditionally.
NOTE: Using GOTO statements is highly discouraged in any programming language because it makes it difficult to track the program's control process, making the program difficult to understand and difficult to modify. Using a goto any program can be rewritten so that it does not need goto.
Grammar
The syntax to go to the Goto statement is as follows:
Copy Code code as follows:
Goto label;
..
.
Label:statement;
Here, the label (label) can be any plain text that is dropped from the keyword, and it can be set anywhere above or below the GO program to use the goto statement.
Flow chart:
Example:
Copy Code code as follows:
Package Main
Import "FMT"
Func Main () {
/* local variable definition * *
var a int = 10
* Do loop Execution/*
Loop:for a < 20 {
If a = = 15 {
/* Skip the iteration * *
A = a + 1
Goto LOOP
}
Fmt. Printf ("Value of a:%d\n", a)
a++
}
}
Let's compile and run the above program, which will produce the following results:
Value of A:10
value of a:11
value of a:12 value of a:13 value of a:14 value of
a:16
value of A:17
value of a:18
value of a:19
Infinite loop
A loop becomes infinitely cyclic if the condition is never false. For loops are traditionally used for this purpose. Because there is no three expression required to form A for loop, you can form a dead loop by leaving the condition, using an empty expression, or passing true.
Copy Code code as follows:
Package Main
Import "FMT"
Func Main () {
For true {
Fmt. Printf ("This loop would run forever.\n");
}
}
When the conditional expression is not present, it is assumed to be true. You may have an initialization and incremental expression, but C programmers are more commonly used for (;; ) structure to represent an infinite loop.
Note: You can terminate an infinite loop by pressing CTRL + C.