M
Mike42
Is there a goto statement or something similar in java? If so, how do I
use it?
use it?
Mike42 said:Is there a goto statement or something similar in java?
If so, how do I use it?
The statements "switch" or "throw" do something similar.
Stefan Ram said:"switch" and "throw" are not statements, but keywords.
A more appropriate wording might be
"The switch- and the throw-statement do something similar."
Is there a goto statement or something similar in java? If so, how do I
use it?
Mike42 said:Is there a goto statement or something similar in java? If so, how do I
use it?
Is there a goto statement or something similar in java? If so, how do I
use it?
At the risk of sounding like an old geezer, every programming course I haveMike42 said:Is there a goto statement or something similar in java? If so, how do I
use it?
Rhino said:At the risk of sounding like an old geezer, every programming course I
have taken in over 20 years of professional programming has strongly
discouraged the use of 'goto' statements. Every experienced programmer I
have met in that time has had the same view,
based on their own
experiences with the unmaintainable mess that results: 'goto' statements
are evil.
Mike42 said:Is there a goto statement or something similar in java? If so, how do I
use it?
Interestingly, the C++ source for the native part of the AWT implementation
makes heavy use of goto in order to /improve/ the clarity, structure, and
maintanability of the code. Works too...
try
{
if (...)
{
if (...)
{
if (...)
{
throw new SomeExceptionType();
}
}
}
}
catch (SomeExceptionType e)
{
}
// continues here{
if (...)
{
if (...)
{
if (...)
{ break outer;
}
}
}
}
I like to think I'm an open-minded guy so I'm willing to concede that 'goto'Chris Uppal said:Clearly we have not met ;-)
Interestingly, the C++ source for the native part of the AWT implementation
makes heavy use of goto in order to /improve/ the clarity, structure, and
maintanability of the code. Works too...
Roedy Green said:outer:
break/continue only work with loop labels, so you need to make a dummy
one around the block, e.g.
outer: while(true) {
// ... statement incl. break or continue
}
If you don't need continue, use do .. while(false) instead.
Interestingly, the C++ source for the native part of the AWT implementation
makes heavy use of goto in order to /improve/ the clarity, structure, and
maintanability of the code. Works too...
I *think* the anti-goto advice is primarily a reaction by structured
programmers to the preceding era of programming.
Luckily, Java doesn't have a 'goto' but, even if it did, you should avoid it
like the plague. Ditto for 'goto' in any other programming language.
Chris said:Interestingly, the C++ source for the native part of the AWT implementation
makes heavy use of goto in order to /improve/ the clarity, structure, and
maintanability of the code. Works too...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.