The other listed answers will work, but I agree with c4pone - in such a loop, a gap looks like a bad way to do this, especially if using break means that if you add another condition around your if, there is a chance that break can no longer function when exiting the for loop - in some ways it is similar to the goto operator in other languages
Another alternative to your problem is the following:
for(int i = 0; i < procInfos.size(); i++){ if(procInfos.get(i).processName.equals("com.me.checkprocess")) { Log.e("Result", "App is running - Doesn't need to reload"); i = procInfos.size(); } else { Log.e("Result", "App is not running - Needs to reload); } }
Which will also break the loop, as it sets your counter variable in a termination clause, which means that once it is detected, the loop will end.
EDIT:
After the OP comment below, I feel that the solution he wants is the following:
boolean found = false; for(int i = 0; i < procInfos.size(); i++){ if(procInfos.get(i).processName.equals("com.me.checkprocess")) { found = true; } } if(found) { Log.e("Result", "App is running - Doesn't need to reload"); i = procInfos.size(); } else { Log.e("Result", "App is not running - Needs to reload); }
Which is not connected with the exit from the cycle prematurely, since we all thought that we were reading the question, and instead we output the result only once
source share