By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

The reason behind the ; is written after loop statement.

P: 1
Why semi colon is written after loop statement, in c.
Oct 24 '15 #1
Share this Question
Share on Google+
4 Replies

P: 13
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:
Expand|Select|Wrap|Line Numbers
  1. do{           
  2.    statements;                    
  4. }while( condition );                      
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 ;.
Oct 24 '15 #2

Expert Mod 5K+
P: 9,197
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.
Oct 24 '15 #3

Expert 100+
P: 2,396
@starx please show us an example of the kind of statement you're asking about.
Oct 26 '15 #4

P: 1
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.
Expand|Select|Wrap|Line Numbers
  1. do
  2.    x += y;
  3. while (x < y);
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.
Expand|Select|Wrap|Line Numbers
  1. if (x < y)
  2.    x += y;
I hope this is the answer you're looking for.
Oct 26 '15 #5

Post your reply

Sign in to post your reply or Sign up for a free account.