Loop breakpoint after a lot of iterations in Eclipse

Suppose I have the following code. During debugging, I want Eclipse to stop when it has completed 1 million iterations. How to do it? I can’t manually do 1 million times.

for(int i = 0; i < 10000000; i++) { //some code } 
+6
source share
3 answers

You can put a conditional break point in eclipse:

  • Place a breakpoint
  • Right click on> Properties
  • Enable Condition
  • Enter condition code

    i == 1,000,000

+10
source

In this case, do the following:

 for(int i = 0; i < 10000000; i++) { if(i==1000000){ // do nothing .... // this is just a dummy place to make eclipse stop after million iterations // just put a break point here and run the code until it reaches this breakpoint // remove this if condition from your code after you have debugged your problem } //your code } 
+2
source

I know that I am a necropolis, but I am answering the @Anarelle question to the currently accepted answer about stopping when there is no variable. This also answers the original question. In the Eclipse conditional interrupt window (in Debug Perspective), you can click on the checkbox next to Number of hits: and just give it several times so that the breakpoint is touched before it pauses execution. Please note that this not only works outside of loops (for example, debugging a pause only after I tried this action 3 times), but also takes into account external loops. For example, in the following code i will be 6 and j 3 when hitting a breakpoint, if the number of hits is 20:

 for (int i = 0; i < 100; i++) { System.out.println(i); for (int j = 2; j < 5; j++) { System.out.println(j); } } 

After the breakpoint has been deleted, it will be disabled until the user restarts it. In other words, this function can also be used to check every 20 times when a particular breakpoint is hit, if it switches on again every time.

+1
source

Source: https://habr.com/ru/post/955379/


All Articles