Can someone explain me the Syntax of a for-loop
like "for (;;)"
what i need to know is whether the header of a for-loop
like "for (;;)"
is having empty-statements
or not.
I searched the ECMAScript specification about what will happen if all the optional expressions within the for-loop's
header is skipped like for (;;)
in the specification but i still didnt find about it
can someone explain me about this even the specification haven't mentioned that a for-loop
like for (;;)
loops/runs infinite times
and i need to know one last thing why people call the header of a for-loop
is having Expression's
i see that the syntax of a for loop allows us to write declarations like var i = 0
in the header of the for-loop
and i see the for-loops
syntax allows us to write semicolons ;
in its header only statements require semicolons
does that mean all the syntax within the for-loop's
header is having Statements
In a standard for loop definition, it would go as follows:
for (var i = 0; i < 5; i++)
{
//Do something here
}
You have your statement being defining i as 0 (var i = 0
). Then, there is the condition/expression that the for loop checks each time as it runs, which in this example checks that i is less than 5 (i < 5
).
So, to address the first part of your question, when you define a for loop as for(;;)
, you are simply defining a loop with no condition that must be met. Therefore, it continues to run/loop forever. This can be done because all parts of the for loop definition are optional. So, there are no "empty-statements
". It is simply defining the for loop without the optional arguments. We fill it in with semicolons instead in order to represent the transition between the empty arguments.