4

Is it possible to have a condition on a breakpoint in Eclipse, and have the breakpoint "activate" after that condition has been met n times?

Say for example, in some sloppy mobile-written pseduocode, the breakpoint's condition is:

int n = 0;
If(i == j){
    n++
    If(n > 400)
        true;
}

With i and j being values in my class.

To please the duplicate-hunt, note that I am not asking how to use a conditional statement, I am asking how I can count the number of times a breakpoint condition is met, then have the breakpoint stop my code. Hit does not do this, nor does using a condition in any way I can figure out.

Kal
  • 43
  • 5

1 Answers1

4

To activate the breakpoint after the condition is met a certain number of times:

  1. Open breakpoints dialog: Ctrl+double-click breakpoint
  2. Check Conditional checkbox
  3. Use following as condition:

    if (i == j) {
        int n = Integer.parseInt(System.getProperty("breakpoint.n", "0"));
        n++;
        System.setProperty("breakpoint.n", "" + n);
        if (n > 400) return true;
    }
    return false;
    
howlger
  • 31,050
  • 11
  • 59
  • 99
Tiago Luna
  • 101
  • 1
  • 7
  • I'm looking to have the breakpoint activate after the *condition* has been met a certain number of times. Hit is triggered everytime the breakpoint is reached, regardless of if the condition is met, and I want the condition to be met n times before the breakpoint works. Therefore, I do not want to use an outside variable variable in this case. – Kal Sep 01 '17 at 23:02
  • @Kal I changed the answer by including one more solution. I hope it's what you need. – Tiago Luna Sep 02 '17 at 00:05
  • Thank you! That answers my question perfectly :) – Kal Sep 02 '17 at 19:13