I've noticed when using while loops in my java programs that when using a boolean type to terminate it does not seem to be working. I typed up something simple to test it. The code completes through i = 9 and then test is printed out as false.
public class LoopTesting {
public static void main(String[] args) {
boolean test = true;
while(test) {
for (int i = 1; i < 10; i++) {
System.out.println(i);
if(i == 5) test = false;
}
}
System.out.println(test);
}
}
EDIT: In response to afzalex's answer I tested this code:
while(test) {
for (int i = 1; i < 10; i++) {
System.out.println(i);
}
test = false;
for(int i = 11; i < 20; i++) {
System.out.println(i);
}
}
and it prints to 19.
false.