简体   繁体   English

C#VS2010不进入循环?

[英]C# VS2010 Not Entering For loop?

The following code is not entering the i for loop. 以下代码未进入i for循环。 I have had problems with my computer and VS2010. 我的计算机和VS2010出现问题。 Is this a coding issue (I am a vb.net programmer programing c#.net) or a vb install issue? 这是编码问题(我是vb.net程序员正在为c#.net编程)还是vb安装问题?

            for(int hi = 1; hi > 10; hi++)
            {
                reply = pingsender.Send(ip, 500, buffer, options);
                avgtime += reply.RoundtripTime;
            }
            //EDIT:
            //All code except for issue taken offline due to company policy
            //sorry for any inconvience

This code is nested in four for loops (that all work) and is runnin, and is meant to put ping statistics in a list box. 这段代码嵌套在四个for循环中(所有循环都起作用)并且运行,并且旨在将ping统计信息放在列表框中。 Sorry for the messy code, I comment and clean after I get the code working. 很抱歉,代码混乱,我在代码正常工作后进行注释和清理。

Thank you in advance for all of your hard work! 预先感谢您的辛勤工作!

for(int hi = 1; hi > 10; hi++)

will never be true; 永远不会是真的; fails at the first test, as 1 is not > 10 . 第一次测试失败,因为1> 10

The middle clause is (essentially) "while" - not "until". 中间子句(基本上)是“ while”-而不是“ until”。 I suspect you need < 10 (for 9 iterations) or <= 10 (for 10 iterations). 我怀疑您需要< 10 (9次迭代)或<= 10 (10次迭代)。

It's hard to guess why the code isn't entering your for loop. 很难猜测为什么代码没有进入您的for循环。 (Especially since the code is just a snippet of the problem.) (特别是因为代码只是问题的摘要。)

I'd suggest that you place a breakpoint on your for loop, then check what the variables are set to. 我建议您在for循环上放置一个断点,然后检查变量设置为什么。 It's always helpful to use your debugger for diagnosis. 使用调试器进行诊断总是很有帮助的。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM