how do you write the "go to" command in java?
like a command that allows me to go back to a previous part of the program and rerun the program in a loop?

Recommended Answers

All 7 Replies

I think its, continue.. Like

checkpoint_1:

while (blabla)
{
continue checkpoint_1;
}

Really, I though it was a goto line statement. Meaning it gives command to the line specified.

Stack Overflow article

I think, its "not yet implented". Or, not commonly used. Im not sure, im not an expert when it comes to goto-lines etc. (Ive heard that you should try to avoid them as mutch as you can).

I've heard that as well.
I don't use them- ever. If I need to, I'll create a function, and just call it.

Really, I though it was a goto line statement. Meaning it gives command to the line specified.

Stack Overflow article

As it points out, "goto" and "const" are reserved words in Java, but not implemented.

They are reserved and implemented in C and C++ -- the languages which primarily inspired Java.

"const" has been largely replaced with "final", in Java.

"goto" just isn't needed. And it's generally a bad idea. If you want to use the "goto" statement, program in C#. >;->

The goto has been known to create unreadable undebuggable "spaghetti" code since the 1960's (The seminal "goto considered harmful" paper of Edsger W. Dijkstra was written in 1968).
It was a simple decision (and 100% correct IMHO) that Java would not have one. Not then, not now, not ever.

Sun's own web site has a white paper on the design of Java which includes

Java has no goto statement1.
Studies illustrated that goto is (mis)used more often than not simply "because it's there". Eliminating goto led to a simplification of the language--there are no rules about the effects of a goto into the middle of a for statement, for example. Studies on approximately 100,000 lines of C code determined that roughly 90 percent of the goto statements were used purely to obtain the effect of breaking out of nested loops. As mentioned above, multi-level break and continue remove most of the need for goto statements.

http://java.sun.com/docs/white/langenv/Simple.doc2.html

Member Avatar for hfx642

Real programmers don't need "goto"s!!
We don't need no stinkin "goto"s!!

Since Procedures and Functions (methods) were invented,
there was no real need to implement a "goto".
Some languages kept them around for backward compatibility purposes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.