Why semi colon is written after loop statement, in c.
The reason behind the ; is written after loop statement.
Collapse
X
-
There is actually a loop statement that we have to write ; and this is the do-while loop that exists in a lot of languages and has this form:
Now, for loops like for, while, if they are empty, i.e. they have no statements in the body, they should be terminated with a ;.Code:do{ statements; }while( condition ); -
The semi-colon must appear at the end of each statement. The do-loop statement is not complete until the ) of the while so you need a semicolon to tell the compiler the statement is complete.Comment
-
Either of two reasons
I assume, by "after", you mean "at the end (of a loop statement)."
The reason a semicolon (;) is written "after" or "at the end of" a loop statement is either that...
a. It is a do-while loop.
b. For other types of loops, it or the last part of the loop has only one line of code to execute, in its body.Code:do x += y; while (x < y);
I hope this is the answer you're looking for.Code:if (x < y) x += y;
Comment
Comment