How to do this in a for-loop:
for (int 1 = 0; i < length; i++) {
if (checkError(i))
continue;
... // happy path
}
You can also use a return statement inside the for-loop if you want to exit the entire function.