1

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)

8
  • 3
    please, show the code Commented May 6, 2019 at 14:21
  • Post code itself, not image of code. Do you expect us to rewrite it to test it out? Commented May 6, 2019 at 14:23
  • if found = m.find() true after the first iteration? Commented May 6, 2019 at 14:24
  • neither of your conditions in your while loop hold true at that point. Why should continue; change that? Commented May 6, 2019 at 14:25
  • What is your expected result? Why do you think it should behave that way? Commented May 6, 2019 at 14:26

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I mistakenly thought the continue would jump to the start of the loop (behind the do { ) and skip the while condition: while(!found || oneMoreLookahead). That is not the case, thanks for help. (Clarification)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.