I'm currently reading through a text file that looks something like this:
123 (1.0,4.4) (4,5)
4 (2,1) (6.1,7) (1,3) (1,2)
...
89122 (3,1) (56.1,1) (1.7,2)
It begins with a number followed by at least one pair of coordinates in the form (x,y). My goal: If one of the coordinates on the line matches what I'm looking for, I want to add the tag (the first number) to an arraylist and then break out of the loop right away. This is what I have so far:
ArrayList<Integer> matches = new ArrayList<Integer>();
BufferedReader reader = new BufferedReader(new FileReader(new File(args[0])));
String pattern = "([0-9.]+),([0-9.]+)";
Pattern p = Pattern.compile(pattern);
Matcher m = null;
String line;
double x,y;
while((line = reader.readLine()) != null) {
String[] temp = line.split(" ", 2); //this splits the tag from the rest of the line, which are pairs of (x,y)
m = p.matcher(temp[1]);
while(m.find()) {
x = Double.parseDouble(m.group(1));
y = Double.parseDouble(m.group(2));
if(x > 100 || y > 100) {
matches.add(temp[0]);
break; // ***this only breaks out of this single if, but what I really want is to break out of the m.find() while loop and get reader to read in the next line.
}
}
}
The problem I'm having is (* * *), commented out in the code above. How do I break out of the loop properly?