Can somebody explain what for(;;) does in C?

Can somebody explain what for(;;) does in C?

1
2
3
for(;;) { while (something) {
  }
}
nested loop.
similar to this
1
2
3
4
5
6
while(true) {
	while (something) {
		//...
	}
	// break condition
}
The for(;;) loop is a way of saying, "forever." It has no condition, and therefore does not test for anything. A non-existent test can never be false(the condition for exiting a loop), and so it will run forever. The while(true) loop is similar because a statement is given to the loop, rather than a predicate. A statement never changes, and since it's 'true', it will never be false and the loop never exits.
it can exit by writing a break condition.
Topic archived. No new replies allowed.