| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Java Programming Ask your Java programming question and help out others with theirs. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi everyone,
I need to use something in java that is similar to the C language goto statement. This is what i have in a function Code:
public int ret()
{
if
{
//something
//something
//This is the part where i need to jump to the end of the
//function and not exit the function
}
//This is the part i need to jump to
//some more code
//some more code
}
I hope someone can help me this problem Thank You Yours Sincerely Richard West |
|
#2
|
|||
|
|||
|
Re: GoTo
Quote:
It has been proven that any program logic can be expressed with the control structures available in todays high-level languages without the use of goto, so the goto's you've used in C in the past weren't really necessary. Programs become easier to follow without them. |
|
#3
|
|||
|
|||
|
Re: GoTo
As _uj says, you never have to use 'goto', and most experienced OO programmers wouldn't dream of using it (except possibly in complex low-level library code). Maybe this is why Java doesn't use it.
There are the 'label', 'break' and 'continue' keywords for use in loops and 'if' blocks, and you can read up on them, but they're best avoided unless they will make the code more readable. The usual reason for an unstructured jump out of a section of code is when something goes wrong - a method can't continue or an error occurs. In the first case, it may be acceptable to make an early return from a method when, for example, its arguments aren't appropriate. In the second case, you can throw an exception. If you want specific recommendations on your own problem, you'll have to be a lot clearer and more detailed about what you're trying to do. At the IFIP congress in 1971 I had the pleasure of meeting Dr. Eiichi Goto of Japan, who cheerfully complained that he was always being eliminated... D. Knuth
__________________
Please use [CODE]...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present. |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|