Why the following do-while loop is valid?
c, do-while, loops
Solution
That code looks like it was written to obfuscate its meaning but if we look at the draft C99 standard section `6.8.5` Iteration statements, the grammar for do while is:
do statement while ( expression ) ;
and statement can be an expression statement which in turn can be a null statement which is what `;` is. So it is the same as:
do
;
while(1);
we can see from section `6.8.3` Expression and null statements paragraph 3 says:
A null statement (consisting of just a semicolon) performs no operations.
Problem
The loop is as follows: ``` do; while(1); ``` Why the above loop is not giving a syntax error? I am using mingw gcc compiler