Java label statement and goto [duplicate]
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 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
andgoto
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? )
精彩评论