Java标签语句和goto
可能的重复:
java中的goto关键字
- java 中没有 goto,对吗?
- 那么为什么 goto 仍然被视为关键字呢?
- 标签语法(仅在循环/if语句之前正确使用*)并通过(标签,中断标签,继续标签)调用
*正确地导致当我在x=3
之前使用它时读完之后还有其他情况吗?
int x = 2;
label: x = 3;
for (int j = 0; j < 5; j++) {
System.out.println(j);
}
label; // Compile error (no local variable label)
Possible Duplicate:
goto keyword in java
- There is no goto in java, right ?
- Why goto is still considered a keyword then ?
- Label syntax (only properly* used before a loop/if statement ?? ) and called through (label, break label, continue label)
*properly cause when i used before x=3
it couldn't be read after it are there any other cases ?
int x = 2;
label: x = 3;
for (int j = 0; j < 5; j++) {
System.out.println(j);
}
label; // Compile error (no local variable label)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 JLS 的第 3.9 节:
From section 3.9 of the JLS:
是的
是的,它是按标准考虑的,[有关官方文档,请参阅 Jon 给出的详细信息链接]
对于标签:请参阅 这个
Yes
Yes it is considered by standards, [for official doc please see details link given by Jon]
For Labels : See this
1 - Java(语言)中没有 goto,Java(虚拟机)中有 goto
2 - 关键字 const 和 goto 被保留,即使它们当前未被使用。如果这些 C++ 关键字不正确地出现在程序中,这可能允许 Java 编译器生成更好的错误消息。 (摘自Java 语言规范)
3 - 问题是什么?
不管怎样,在去SCJP之前先读几遍The java语言规范(现在不是OCJP了吗?)
1 - There is no goto in Java (the language), there is goto in Java (the virtual machine)
2 - The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs. (from The java language specification)
3 - what is the question?
Anyway, read the The java language specification several times before going to SCJP (isn't OCJP now? )