• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to exit the program explicitly.  RSS feed

 
garg sumit
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the if blocks now i want to quit program as soon as any one of them performs with its conditions.
in c-programming we can do this by using exit() function inside each if block....but how to make this happen here ...
 
sathish Lakshminarayanan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in order quit from the java execution you can use exit(); function , to exist from if condition and then execute the rest you can use "break;"
 
garg sumit
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use
System.exit(0);
 
Vib Mator
Greenhorn
Posts: 6
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.exit(n) terminates the JVM.... so its the proper way to exit the program explicitly. you can always provide a number n..
n =0 is generally used to show successful completion..
if you know a point where in your program may differ from what you want to do....
say for a condition where you think you would never reach....if it reaches there.
you can always return n with any value such as 1.... by looking at value of n , you can determine whether the program completely successfully or not...

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!