Is there a rule regarding which statements don’t need to be terminated with a semicolon?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it’s covered in section 6, “Statement” of the C++ standard (section 6 of C++03, it may have changed in C++11 but I don’t have access to that one at the moment).
There are a large number of statement types and not all of them need to be terminated. For example, the following
ifis a selection statement:and there is no requirement to terminate that with a semi-colon.
Of the different statements covered, the requirements are:
(a) Although it may sometimes appear that these are terminated with a semi-colon, that’s not the case. The statement:
has the semi-colon terminating the inner expression statement, not the compound statement, somthing that should be obvious when you examine the first code segment above that has it inside
{}braces.(b)
dorequires the semi-colon after thewhileexpression.