Goto statements

未匹配的标注

A “goto” statement transfers control to the statement with the corresponding label within the same function.

GotoStmt = “goto” Label .

goto Error

Executing the “goto” statement must not cause any variables to come into scope that were not already in scope at the point of the goto. For instance, this example:

goto L  // BAD
v := 3

L:

is erroneous because the jump to label L skips the creation of v.

A “goto” statement outside a block cannot jump to a label inside that block. For instance, this example:

if n%2 == 1 {
    goto L1
}
for n > 0 {
    f()
    n--
L1:
    f()
    n--
}

is erroneous because the label L1 is inside the “for” statement’s block but the goto is not.

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
讨论数量: 0
发起讨论 只看当前版本


暂无话题~