Results 1 to 4 of 4
Thread: How to stop executing method
- 12-31-2009, 09:14 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 15
- Rep Power
- 0
How to stop executing method
I have a method called menu() which is the controlling method in the programm and this method calls other methods what i need is when a condition happens in any of the other methods(that are called by menu) happens to stop this methods and go back to the menu method()
Java Code://what i need //e.x add() //if some condition is false //stop executing this method //go back to menu()
but i know that what i do that i call the menu method but the add()method is still in execution!!Java Code://what i do add() //if some condition is false menu();
thanx in advance!!!
- 12-31-2009, 09:22 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
If you called the add method from the menu method, then the menu method will continue to execute after the add method returns. You can put a return statement at any point in the add method to force this return to happen before the end of the add method is reached.
Don't forget that the return will return the code execution to the point in the menu method from where the add method was called.
- 12-31-2009, 10:29 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 15
- Rep Power
- 0
thank you for your reply!!!
but isn't there other ways to do this??!!
As i knew that using break or return statments to break the flow is not a good habbit that decrease code readabilty!!!
Am i right?!?!?!
and thanx again!!:D
- 12-31-2009, 10:33 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Thread Stop() method not working
By charan reddy in forum Threads and SynchronizationReplies: 18Last Post: 10-03-2009, 03:01 PM -
Help to stop a thread
By raghu_lzybns in forum New To JavaReplies: 4Last Post: 07-09-2009, 04:39 PM -
How to stop thread from being jumping off the code without executing it.....
By chiragkini in forum Threads and SynchronizationReplies: 6Last Post: 01-22-2009, 03:38 AM -
Can you stop a gif? xd
By Exhonour in forum New To JavaReplies: 0Last Post: 01-16-2009, 08:44 PM -
executing a method in main class
By rangers27 in forum New To JavaReplies: 3Last Post: 07-19-2008, 05:04 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks