I know that the for loop syntax is like :
for(initialise; condition ; increament/decreament)
but what will be the output for the following:
for( ; ; )
{
printf("hello world");
}
I know that the for loop syntax is like :
for(initialise; condition ; increament/decreament)
but what will be the output for the following:
for( ; ; )
{
printf("hello world");
}
This has to do with standards for C in general.
6.8.5.3 The for statement
The statement
for ( clause-1 ; expression-2 ; expression-3 ) statement
behaves as follows: The expression expression-2 is the controlling expression that is evaluated before each execution of the loop body. The expression expression-3 is evaluated as a void expression after each execution of the loop body. If clause-1 is a declaration, the scope of any identifiers it declares is the remainder of the declaration and the entire loop, including the other two expressions; it is reached in the order of execution before the first evaluation of the controlling expression. If clause-1 is an expression, it is evaluated as a void expression before the first evaluation of the controlling expression.
Both clause-1 and expression-3 can be omitted. An omitted expression-2 is replaced by a nonzero constant.
References
<http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf>
<https://stackoverflow.com/questions/13366290/why-can-the-condition-of-a-for-loop-be-left-empty>
No conditions are specified in the for
loop, therefore the loop will run forever.
https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Infinite_loop.html
That will loop forever, printing Hello World every time through the loop. Another way to achieve this same result is by doing:
while(1){
printf("Hello World");
}
Also use indentation. it helps with readability (not a problem in your example, but with bigger problems it would be an issue.