What kind of loop is for (;;)?

2019-02-12 01:03发布

Found in torvalds/linux-2.6.git -> kernel/mutex.c line 171

I have tried to find it on Google and such to no avail.

What does for (;;) instruct?

12条回答
手持菜刀,她持情操
2楼-- · 2019-02-12 01:24

It literally means "do nothing, until nothing happens and at each step, do nothing to prepare for the next". Basically, it's an infinite loop that you'll have to break somehow from within using a break, return or goto statement.

查看更多
地球回转人心会变
3楼-- · 2019-02-12 01:24

I means:

#define EVER ;;

for(EVER)
{
     // do something
}

Warning: Using this in your code is highly discouraged.

查看更多
Emotional °昔
4楼-- · 2019-02-12 01:25

for(;;)

is an infinite loop just like while(1). Here no condition is given that will terminate the loop. If you are not breaking it using break statement this loop will never come to an end.

查看更多
家丑人穷心不美
5楼-- · 2019-02-12 01:27

It's equivalent to while( true )

Edit: Since there's been some debate sparked by my answer (good debate, mind you) it should be clarified that this is not entirely accurate for C programs not written to C99 and beyond wherein stdbool.h has set the value of true = 1.

查看更多
The star\"
6楼-- · 2019-02-12 01:30

It is an infinite loop which has no initial condition, no increment condition and no end condition. So it will iterate forever equivalent to while(1).

查看更多
男人必须洒脱
7楼-- · 2019-02-12 01:30

it is an infinite for loop.

查看更多
登录 后发表回答