Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exit Sub in java?

 
MR Chahal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok i have changed it. How can i stop a code from executing any further?
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21199
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
MR Chahal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello and thank you Henry. That is exactly what i was looking for
[ April 15, 2006: Message edited by: MR Chahal ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic