473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

The reason behind the ; is written after loop statement.

1
Why semi colon is written after loop statement, in c.
Oct 24 '15 #1
4 1215
zuko32
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;                    
  3.  
  4. }while( condition );                      
  5.  
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
weaknessforcats
9,208 Expert Mod 8TB
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
donbock
2,426 Expert 2GB
@starx please show us an example of the kind of statement you're asking about.
Oct 26 '15 #4
AX3M
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

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

Similar topics

17
by: David Isaac | last post by:
I would like to be able to define a loop statement (nevermind why) so that I can write something like loop 10: do_something instead of for i in range(10): do_something
4
by: Madhav | last post by:
Hi all, I am a newbie in c++. I want to know what is the philosophical reason behind the existence of friend functions. I thought giving access to private data to a function which is not a member...
7
by: DaVinci | last post by:
I am writing a pong game.but met some problem. the ball function to control the scrolling ball, void ball(int starty,int startx) { int di ,i; int dj,j; di = 1; dj = 1; i = starty;
26
by: Bill Norton | last post by:
If you wrap one division around another like this: <div id="wrapper"> <div id="child">...</div> </div> ....the wrapper division will be considered the containing block of the child division...
2
by: travhale | last post by:
in a new project using .net 2005, c#. getting err message "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." source RDBMS is oracle 8i. I add a new...
3
by: pannu | last post by:
tell me the output of the following c program and the reason behind it main() { int a=400; int b; b=a*a/a; printf("%d",b); }
2
by: JReneau35 | last post by:
I am trying to run a loop statement that compares two tables. We will call them TableA & TableB and pks of LastNameA (tableA) and LastNameB (tableB). TableA is a table that was created some time...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.