Problem in loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhoriya22
    Contributor
    • Jul 2007
    • 251

    #16
    Originally posted by joloms38
    hi. there..

    how to use while loop in java using an exit?....
    my problem is, i can not exit the program using the loop given to me...
    please help me.....

    inside while loop put a condition when u want to exit........in that condition give System.exit(0). .........

    Comment

    • itsraghz
      New Member
      • Mar 2007
      • 124

      #17
      Originally posted by madhoriya22
      inside while loop put a condition when u want to exit........in that condition give System.exit(0). .........
      Don't use System.exit(0) unnecessarily. Instead try having a boolean variable as a "flag" and have a conditional execution based upon its value. Make sure you set the flag variables value once you have reached the condition.

      Use the features sparingly. Just because its present does not mean you can use everywhere.

      Comment

      Working...