Using break in a large for loop (or set thereof...)
in
Programming Questions
•
2 years ago
Hi..
I've never used break before, but think it may be what I need in my current situation, and I'm wondering if anyone has any advice on it's use...
I'm reading through a text file with loadStrings() and a for loop. Currently, my text file is formatted so that every three lines I have
String // file name
String // latitude
String // longitude
repeat....
Currently, what I'm doing is reading through it like such
for(i = 1; i < lines.length; i += 3)
so that it's reading for a match on the 2nd (and 5th, 8th, etc) line
if(lines[i].equals(Latitude) == true) {
// printing, statements, etc
break; // this is where I thought to put the break....
}
but the tricky bit is that I am also reading for a mismatch, so directly afterwards I have
else if(lines[i].equals(Latitude) == false){
//printing, statements, etc
}
of course, since this is within a for loop, I am getting a match followed by multiple mismatches.
Now, I thought that if I got a true match, and put it in a break statement, it would exit the for loop and would not attempt to execute, but it is - I am still seeing all my println's, etc...
Can anyone see anything obvious that I may be doing wrong? Or have any better idea about how to structure my code?
Thanks in advance,
~ J
1