| Author |
Exit Sub in java?
|
MR Chahal
Greenhorn
Joined: Nov 27, 2005
Posts: 14
|
|
Hello What is the equalant of 'Exit Sub' from visual basic in java? For example: s1(); s2(); if a = b then exit sub s3(); so if a is equal to b then the code will stop and not go on to executing s3() [ April 15, 2006: Message edited by: IG IT ]
|
 |
Ankur Sharma
Ranch Hand
Joined: Dec 27, 2005
Posts: 1234
|
|
You can use System.exit(0) if you want to exit your programe. And if you want to switch from function just write down a retrun statement there. It will automatically switch your programme to the main function from where it was called earlier. Anything more you want to knwo just let me know. Anything of Something is better then Something of Anything.
|
 |
MR Chahal
Greenhorn
Joined: Nov 27, 2005
Posts: 14
|
|
Hello Ankur when i use the System.exit(0) my program closes. I dont want my program to close but rather to stop the code to execute any futher. How can i do that?
|
 |
Ankur Sharma
Ranch Hand
Joined: Dec 27, 2005
Posts: 1234
|
|
I think Your Name doesn't follow the naming conventions of this forum. CHeck out this link Naming Policies on JAVA Ranchers Anything of Something is better then Something of anything.
|
 |
MR Chahal
Greenhorn
Joined: Nov 27, 2005
Posts: 14
|
|
|
Ok i have changed it. How can i stop a code from executing any further?
|
 |
Ankur Sharma
Ranch Hand
Joined: Dec 27, 2005
Posts: 1234
|
|
I cann't understand your problem pls let us know the logic of your function And the another thing is, what you really mean by Stopping function. Either you need to close the application otherwise you want to switch the main function which called this function. For closing the program you should use: System.exit(0); For switching to the calling function. Use return statement; FOr continuing to other line of another function you should use... Break statement Let me know if still any concern.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
I believe "exit sub" tell visual basic to exit the procedure. The closest analogy to a procedure is a method call. And to exit from a method call you use "return". Something like this... Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
MR Chahal
Greenhorn
Joined: Nov 27, 2005
Posts: 14
|
|
Hello and thank you Henry. That is exactly what i was looking for  [ April 15, 2006: Message edited by: MR Chahal ]
|
 |
 |
|
|
subject: Exit Sub in java?
|
|
|