Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging java for loop: skip to a specific iteration

I'm working on a java project in Netbeans. I have a for loop which runs 29 times and each iteration takes about 1 minute to complete. The problem is in the 29th iteration of the loop. Is there any way that I can SKIP the first 28 iterations and go directly to the one in question?

I know I can put a conditional breakpoint, but that dosent make the debugger skip the iterations, it just notifies me when a paticular iteration is reached.

Please Help! Otherwise, this would take a awful lot of time to debug!

like image 259
Sid Avatar asked Oct 15 '25 19:10

Sid


2 Answers

You could use something like the Java Platform Debugger Architecture. That might help. On the other hand, you could do something like so:

for (int i = 0; i < ...; i++)
{
    if (i == 28)
    {
         System.out.println("Line Found"); //put breakpoint here
    }

    //remainder of the code.
}

This should allow you to trigger a breakpoint on the 29th execution of the loop and you can then use the step functions offered by the debugger to go over the code for the 29th iteration.

I have never used the JPDA, and even if I did I think that the most simple and straight forward solution would be to do something like the code above.

like image 98
npinti Avatar answered Oct 18 '25 11:10

npinti


You could put a temporary line of code inside your loop, and put a breakpoint on that:

if (i=29) {
    // Put a breakpoint on this line (only hit if i=29)
}
like image 45
MattR Avatar answered Oct 18 '25 12:10

MattR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!