开发者

strange for loop? C# [duplicate]

开发者 https://www.devze.com 2023-01-27 07:41 出处:网络
This question already has answers here: Closed 12 years ago. P开发者_开发知识库ossible Duplicate:
This question already has answers here: Closed 12 years ago.

P开发者_开发知识库ossible Duplicate:

In C# is a for(;;) safe and what does it really do?

So i recently came across something ive never seen before..

        for (; ; )
        {

        }

What is exactly happening when the feilds are left blank like that?


It's an infinite loop.

Somewhere inside there should be a break; statement, or possibly an exception thrown in order for control to pass beyond the loop.

You could also achieve the same thing (probably more obviously) by doing

while (true)
{
    // do stuff
}


This is an infinite loop, almost equivalent to a while(true) loop.

The break condition is not there in between the two semicolons, therefore, it must be there somewhere in the loop body.


That's an infinite for loop.

0

精彩评论

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

关注公众号