如何在 Visual Studio 调试器中的某个点中断循环?

发布于 2024-07-24 06:12:06 字数 161 浏览 2 评论 0原文

我有一个 for 循环,它在字符串数组上运行 1000 多次。

我想让我的应用程序在其中一个字符串与某个术语匹配时中断。
所以我可以从那时开始浏览我的代码。

现在,我知道我可以添加一段代码来查找它并在它命中时添加一个断点,但是没有办法在调试器中执行此操作吗?

I have a for-loop which runs for 1000+ times over a string array.

I want to have my app break when one of the strings matches a certain term.
So I can walk through my code from that point.

Now, I know I can add a piece of code that looks for this and a breakpoint when it hits, but is there not a way to do this in the debugger?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鱼窥荷 2024-07-31 06:12:07

转到您的代码,

  1. 创建一个断点
  2. ,右键单击左侧的红点,
  3. 选择条件
  4. 输入类似i == 1000的内容

,或者

在循环中间

写入

if (i == 1000){
  int a = 1;
}

并中断整数a=1;

第二种方法看起来更像是垃圾,但我发现它更容易、更快

Go to your code

  1. create a breakpoint
  2. right click on the red dot on the left
  3. select condition
  4. put something like i == 1000

or

at the middle of your loop

write

if (i == 1000){
  int a = 1;
}

and break over int a = 1;

The second method looks more like garbage, but I find it easier and faster to do

来日方长 2024-07-31 06:12:07

是的,您可以在调试器中。 这称为“条件断点”。 基本上,右键单击红色断点并转到“条件”选项。

谷歌快速浏览了this up:

PS 最后一张是VS 2005,不过2008年也是这样。

Yes, you can in the debugger. It's called a "conditional breakpoint." Basically, right click on the red breakpoint and go to the "condition" option.

A quick google turned this and this up:

P.S. The last one is VS 2005, but it's the same in 2008.

江心雾 2024-07-31 06:12:07

在 Visual Studio 中,您可以设置条件断点:

  • 照常在要中断的点处设置断点。
  • 右键单击左边距中的红点,然后
    选择“条件断点...”。
  • 当您想要中断时,输入一个计算结果为 true 的表达式,
    (例如 i == 1000,或 MyString =“hello world”)

In Visual Studio you can set a conditional breakpoint:

  • Set a breakpoint at the point you want to break as normal.
  • Right click on the red dot in the left margin and
    select "Conditional Breakpoint...".
  • Type an expression that evaluates to true when you want to break,
    (e.g. i == 1000, or MyString = "hello world")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文