This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Exit Sub in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exit Sub in java?" Watch "Exit Sub in java?" New topic
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 ]
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

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?
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

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?
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

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: 18545
    
  40

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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exit Sub in java?
 
Similar Threads
Intra Ranch Go Game!
String Objects
Doubt in Strings
== operator returns true for Strings
cast