Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

breaking out of a recursion

809475Jan 9 2009 — edited Jan 11 2009
hello all,

I have a recursive method in a java program.
the main program contains a for loop which calls the recursive method for a certain number of times.

the recursive method obviously calls itself. so I have stacks generated during the program execution.
how can I end the recursive method when it has called itself more than once.
and return back to the main program for the next iteration?

program structure is something like this:
private method (int, string){

    // some code
    //

    method (int, string) 

    // Say that I want to return to main() here
}


public main () {

    // some code
    //
    
    for (int i = 0; i <= somenum; i++) {

            // some code

            method (int, string) // i'll have different argument values for each call
    
   }
}
I know about System.exit(). But that stops the program execution.
I need to keep the method running for the next "for" iteration.
Also "return;" will pass program execution to the previous stack. which I don't want.

Any Ideas/Suggestins??
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 8 2009
Added on Jan 9 2009
11 comments
2,738 views