Reputation: 615
Suppose I have the following code. While debugging, I want Eclipse to stop when it has done 1 million iterations. How to do this? I cannot manually do 1 million times.
for(int i = 0; i < 10000000; i++) {
//some code
}
Upvotes: 9
Views: 7953
Reputation: 21
I know I'm necroing, but I'm answering the question from @Anarelle on the currently accepted answer about stopping when no variable is available. This also answers the original question. In Eclipse's conditional breakpoint window (in Debug Perspective), you can click on the checkbox next to Hit count: and simply give a number of times that breakpoint should be "touched" before it pauses execution. Note that not only does this work outside of loops (eg. pause debugging only after I've tried this action 3 times), but it also takes outer loops into account. For example, in the following code, i
will be 6 and j
3 when the breakpoint is hit, if my hit count is 20:
for (int i = 0; i < 100; i++) {
System.out.println(i);
for (int j = 2; j < 5; j++) {
System.out.println(j);
}
}
Once the breakpoint has been hit, it will be disabled until re-enabled by the user. In other words, this feature can also be used to check every 20 times a particular breakpoint is hit, if re-enabled every time.
Upvotes: 2
Reputation: 5565
In that 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
}
Upvotes: 4
Reputation: 645
You can put conditional break point in eclipse:
Put condition code
i == 1000000
Upvotes: 15