打破和标签,“标签MyLabel缺失” [英] break and label, "The label MyLabel is missing"

查看:798
本文介绍了打破和标签,“标签MyLabel缺失”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

if(condition1)
{
    break MyLabel;
}
while(true)
{
    //some code here
    MyLabel: if(condition2) break;
    //more code here
}

我收到此错误:


标签MyLabel缺失。

The label MyLabel is missing.

出了什么问题?

推荐答案

您只能分解到文本封闭语句中的标签。在您的示例中,标签不在包含 break 语句的语句中。

You can only break to a label that is on a textually enclosing statement. In your example, the label is NOT on a statement that encloses the break statement.

(因为它是什么值得的,甚至更高级别的语言支持<$​​ c $ c> goto 不允许你从外面跳到循环的中间。我在考虑C ......和像FORTRAN这样的老语言。)

(For what it is worth, even higher-level languages that support goto don't allow you to jump into the middle of a loop from the outside. I'm thinking of C ... and older languages like FORTRAN.)

Java允许你突破,但闯入是非法的...并会让你被捕: - )

Java allows you to break out, but breaking in is illegal ... and will get you arrested :-)

(对不起,我无法抗拒。对于那些不开玩笑的人来说,闯入是指有人进入你的房子偷东西 - 见休息并输入 ...)

(Sorry, I couldn't resist it. For those who don't get the joke, a "break in" is when someone enters your house to steal stuff - see "break and enter" ... )

这篇关于打破和标签,“标签MyLabel缺失”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆