做while循环C# [英] do while loop in C#
问题描述
您好我是新来的C#编程能有人给我如何写做while循环C#
Hi I am new to programming in C# can some one give me an example of how to write do while loop in C#
编辑例如:仅供参考我是一个VB。 .NET编程试图使移动到C#,所以我确实有.NET / VB语法的经验。 !再次感谢
FYI I am a VB.NET programming trying to make the move to C#, so I do have experience with .NET / VB syntax. Thanks again!
推荐答案
的一般格式为:
do
{
// Body
} while (condition);
其中,条件
是类型的某些表达< 。code>布尔
我个人很少写做/ while循环 -
,的foreach
直,而
循环是在我的经验更为常见。后者是:
Personally I rarely write do/while loops - for
, foreach
and straight while
loops are much more common in my experience. The latter is:
while (condition)
{
// body
}
之间的,而
和<$ C $的区别C>做...而的是,在第一种情况下,身体会的从不的进行,如果条件为假开始与执行 - 而在后一种情况下它一直执行一旦前的状况是不断进行评估。
The difference between while
and do...while
is that in the first case the body will never be executed if the condition is false to start with - whereas in the latter case it's always executed once before the condition is ever evaluated.
这篇关于做while循环C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!