View Single Post
  #2 (permalink)  
Old 08-07-2007, 06:29 AM
cachi cachi is offline
Member
 
Join Date: Jul 2007
Posts: 40
cachi is on a distinguished road
You can do this in one of two ways in Java. There are break statements and using boolean statements you can take advantage of.

Break statements will break out of a loop right when it gets to the statement. So if we were to do
Code:
int i = 0; while(true) { if(i > 3) break; i++ }
This loop would break when I becomes greater then three.

That is one way. The other way to separate execution would be to use a boolean variable to keep track of what is going on when. For example

Code:
boolean found = false; for(int i = 0; i < somelist.length() && !found; i++) { if(something.equals(somethingelse)) found = true; } if(!found) System.out.println("Not Found"); else System.out.println("Found");
Greetings.
Reply With Quote