对于(;;)或while(true),哪个是正确的C#无限循环? [英] Which is the correct C# infinite loop, for (;;) or while (true)?

查看:138
本文介绍了对于(;;)或while(true),哪个是正确的C#无限循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

回到我的C / C ++时代,将无限循环编码为

Back in my C/C++ days, coding an "infinite loop" as

while (true)

相对于

for (;;)

PC-lint 和随后的最佳实践讨论打破了我的这种习惯。此后,我使用 for 控制语句对循环进行了编码。今天,很长一段时间以来的第一次,也许是我作为C#开发人员的第一个无限循环需求,我正面临着同样的情况。

An encounter with PC-lint in the late 1980's and subsequent best practices discussions broke me of this habit. I have since coded the loops using the for control statement. Today, for the first time in a long while, and perhaps my first need for an infinite loop as a C# developer, I am facing the same situation. Is one of them correct and the other not?

推荐答案

while(true)
{

}

我总是用过什么,用过什么我见过其他人使用必须手动中断的循环。

Is always what I've used and what I've seen others use for a loop that has to be broken manually.

这篇关于对于(;;)或while(true),哪个是正确的C#无限循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆