views:

105

answers:

4

I am trying to find an error in my code. The problem is the error occurs in a loop. But the loop iterates about 500 times. Instead of clicking through the loop. Is it possible to skip over a certain amount of the loop ??

+9  A: 

VS allows you to set a condition on a breakpoint in terms of variables that are in scope. So, in your case, you can test against the loop counter.

Troubadour
ok, I found it. Just right click on the break point and select hit count
numerical25
+3  A: 

Here is a crude answer:

if ((iter % 10) == 0) {
    int stop = 1;
}

Then place a break-point at "int stop = 1;". Perhaps, there is a better way in VS but this is what I do from time-to-time.

Anon
+1 That is the IDE implementation agnostic solution.
Elijah
Quite. Just take the code out before you check in lest you make thedailywtf.
Joshua
If you want to do that, surround that code with `#ifdef DEBUG` / `#endif` so that it's not part of your production build.
R Samuel Klatchko
Conditional break-points can sometimes slow down your execution speed by a ridiculous amount. So if you need to skip millions or iterations instead of hundreds, this method can help preserve sanity.
Alan
+1  A: 

You can assign new values to variables during debug session. Step through the loop statements as many times as you like, then set your loop counter (or whatever other vars maintain loop condition) to terminate the loop.

Nikolai N Fetissov
I'm not sure this is what he's looking for but something every programmer should know anyway.
caspin
The keyword is *should*, we should know many things ...
Nikolai N Fetissov
A: 

Just put the breakpoint in the loop like indicated below >>. Use F5 to get to the condition that causes failure so you can loop through the individual pass. How to know where to break is up to you.

for (int i = 0; i < LOOPMAX; i++) {
>>some_proc(i);
  some_other_proc(i);
  some_third_proc(i);
}

By pressing F5 it'll continue running till it gets to the next breakpoint (the next pass through the code). Sure you'll have to hit it 500 times, but that beats some thousands of times. Combine this with @Troubador code above.

PS: This answer IS really simple, but some people don't know they can do this.

drachenstern