At the moment, I have this:
do{
if (i < y){ //y is a constant
ObsHandler.obsPartsHandler(); //increment i twice
ObsHandler.search();
}
else {
break;
}
} while (!endline.equals(null)); // endline is changed during each loop cycle
With this loop, and the inputs I have, endline can not be null; this renders the while loop breaking condition redundant. When I try and convert this loop to a for loop, I get a misplaced construct error from Eclipse.
i.e:
for (i < y) {
ObsHandler.obsPartsHandler(); //increment i twice
ObsHandler.search(); }
Whilst, the while loop I have works, it seems like bad practice to me.
Any suggestions? Thanks.
If you don’t need to check
endLine, you can still use a while loop:If you also need to check
endLine:Note: the difference between do / while (your initial code) and while { } is that in the first case the loop is always run at least once. With a while { }, it is not run at all if the condition is not true at the beginning. That is the same behaviour as a for loop (won’t run if the condition is false before the loop).