开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜