C#: While loops with the condition at the end
In VB I can write a loop that always executes at least once. For example:
Do
[code]
Loop While [c开发者_如何学运维ondition]
Is there a way to do that in C#?
Sure:
do
{
...
} while (condition);
See do (C# Reference)
.
do
{
// code
} while (condition)
Alternatively
bool finished = false ;
while ( !finished )
{
// do something
finished = // evaluate a new foo
}
I've never been a huge fan of do/while
TopOfLoop:
// ...
if (condition)
{
goto TopOfLoop;
}
No career is complete without at least one goto
.
精彩评论