Corals
Corals

Reputation: 13

Continue instruction of while loop not executed

A continue instruction in a while loop is not executed. In Eclipse Debugging, the loop just breaks after the System.out.

Anyone know what may cause this, is there a way to debug on cpu instruction level to see what happens ?

  do { // recursive calls through element.parents() until the formula pattern (patternFormula) matches
                counter++;
                System.out.println(counter);
                lookupElement = lookupElement.parent();

                String s = replaceArrowTagAndClean(lookupElement.html()); // replace <img .. src=> and return text()

                m = patternFormula.matcher(s);
                if( (found = m.find()) ) {
                    oneMoreLookahead = false;
                    System.out.println("Continue " + counter);
                    continue;
                }
            } while(!found || oneMoreLookahead);

            System.out.println("End");

Output is:
1
2
3
4
Continue 4
End

(Sry, had quite some trouble creating this post. lol)

Upvotes: 1

Views: 178

Answers (1)

Davide Lorenzo MARINO
Davide Lorenzo MARINO

Reputation: 26926

The instruction continue will skip all the following lines of code in the loop and will go to the next iteration.

If you place the continue as the last line of code of the loop the behaviour leaving that instruction or removing it is the same.

In your case you can simply use the break instruction to exit the loop immediately.

Upvotes: 1

Related Questions