1

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 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)
Community
  • 1
  • 1
Ismail Marmoush
  • 13,140
  • 25
  • 80
  • 114
  • similar (possible duplicate) questions: http://stackoverflow.com/questions/1334376/goto-keyword-in-java and http://stackoverflow.com/questions/2430782/alternative-to-goto-statement-in-java – Grzegorz Szpetkowski Jul 11 '11 at 12:55

3 Answers3

6

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
3

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

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
1

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

Pablo Grisafi
  • 5,039
  • 1
  • 19
  • 29