0

HI,

I have a for loop

for(int i=0;i<=1000;i++)
{

}

I want to stop the for loop for an particular value like i=100 without applying break point. so how can we achieve it?

3
  • Why don't you want to use break; ? Commented May 2, 2011 at 9:23
  • Why is that without break? I want you to stop doing that algo but you cant stop typing the code? Is this what you mean? Commented May 2, 2011 at 9:23
  • What are you mean under "stop the for loop"? Do you intend to exit out of loop or just debug break? Commented May 2, 2011 at 9:28

3 Answers 3

3
if(i==100) break; // exits the loop

Or

if(i==100 && Debugger.IsAttached)
    Debugger.Break(); // pauses the IDE
Sign up to request clarification or add additional context in comments.

2 Comments

I like the whole Debugger thing, never knew about that. Is that VS2010 feature only?
@Chuck - no, I think that goes way back
1

You can use Debugger.Break() in conjunction with Debugger.IsAttached.

Comments

0

You can achieve it with using breakpoint.

Right-click on breakpoint and click condition. Set your conditions there.

Refer to this link for further info. :D

2 Comments

This applies a breakpoint. The asker specifically requested a solution that does not involve breakpoints.
The problem with conditional breakpoints is that they are dead slow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.