对于(;)或同时(真) - 这是正确的C#无限循环? [英] for ( ; ; ) or while ( true ) - Which is the Correct C# Infinite Loop?

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

问题描述

回到我的C / C ++天,编码一个无限循环为

 ,而(真)

感觉更自然,显得比较明显,我,而不是

 为(;)

在1980年代后期和随后的最佳实践的讨论 PC-皮棉的遭遇打破了我这个习惯。我因为codeD使用控制语句的循环。今天,首次在很长一段时间,也许是我对一个无限循环的C#开发人员首先需要,我面临着同样的情况。就是其中之一正确的,其他的没有?


解决方案

 ,而(真)
{}

总是我所用,什么我见过别人使用具有手动打破了一个循环。

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

while ( true )

felt more natural and seemed more obvious to me as opposed to

for ( ; ; )

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.

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

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