开发者

Java label statement and goto [duplicate]

This question already exists: Closed 11 years ago.

Possible Duplicate:

goto keyword in java

  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)

*properly cause when i used before x=3 it couldn't be rea开发者_Go百科d 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)


From section 3.9 of the JLS:

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.


There is no goto in java, right ?

Yes

Why goto is still considered a keyword then ?

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

For Labels : See this


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? )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜