java Java标签语句和goto

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6650343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:48:05  来源:igfitidea点击:

Java label statement and goto

javalabelgoto

提问by Ismail Marmoush

Possible Duplicate:
goto keyword in java

可能的重复:
java 中的 goto 关键字

  1. There is no goto in java, right ?
  2. Why goto is still considered a keyword then ?
  3. Label syntax (only properly* used before a loop/if statement ?? ) and called through (label, break label, continue label)
  1. java中没有goto,对吧?
  2. 为什么 goto 仍然被认为是一个关键字呢?
  3. 标签语法(仅在循环/if 语句 ?? 之前正确*使用)并通过(标签、中断标签、继续标签)调用

*properly cause when i used before x=3it couldn't be read after it are there any other cases ?

*正确原因当我之前使用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)

回答by Jon Skeet

From section 3.9 of the JLS:

JLS 的第 3.9 节

The keywords constand gotoare 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.

关键字constandgoto是保留的,即使它们当前未使用。如果这些 C++ 关键字错误地出现在程序中,这可能允许 Java 编译器生成更好的错误消息。

回答by Jigar Joshi

There is no goto in java, right ?

java中没有goto,对吧?

Yes

是的

Why goto is still considered a keyword then ?

为什么 goto 仍然被认为是一个关键字呢?

Yes it is considered by standards, [for official doc please see details link given by Jon]

是的,它是按标准考虑的,[有关官方文档,请参阅 Jon 提供的详细信息链接]

For Labels : See this

对于标签:看这个

回答by Pablo Grisafi

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?

1 - Java(语言)中没有 goto,Java(虚拟机)中有 goto
2 - 关键字 const 和 goto 是保留的,即使它们当前未使用。如果这些 C++ 关键字错误地出现在程序中,这可能允许 Java 编译器生成更好的错误消息。(来自Java 语言规范
3 - 问题是什么?

Anyway, read the The java language specification several times before going to SCJP (isn't OCJP now? )

反正去SCJP之前多读几遍Java语言规范(现在不是OCJP了吗?)