In a c/c++ file I discovered a strange for loop
for (;;) {...}
I don't know if this runs once, infinetly or works in some other way Source: https://git.kernel.org/cgit/linux/kernel/git/jejb/efitools.git/tree/PreLoader.c Line 87
In a c/c++ file I discovered a strange for loop
for (;;) {...}
I don't know if this runs once, infinetly or works in some other way Source: https://git.kernel.org/cgit/linux/kernel/git/jejb/efitools.git/tree/PreLoader.c Line 87
The for(;;) loop will continue forever until some command inside the loop causes it to terminate.
Some examples of such commands would be "break", or "return"
In the Linux kernel, infinite loops are written like this, instead of the usual while(true)
or while(1)
in other projects. This is a matter of style.
That is an infinite loop. It's an ordinary for
loop with no condition expression. It is equivalent to while(1)
. It is a bit odd to the eyes of nearly all C
and C++
programmers, and should be avoided. I think people from a C/C++
background are more likely to prefer while(1)
rather than for(;;)
.
K&R 2nd ed 3.5:
is an ``infinite'' loop, presumably to be broken by other means, such as a break or return. Whether to use while or for is largely a matter of personal preference.
It's an infinite loop, equivalent to while(true). When no termination condition is provided, the condition defaults to true.