Although the question has already been answered, an alternative could be this: for (int i = 0; i < foos.size() && try == true; i++) { //Do something... }