473,396 Members | 2,004 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,396 software developers and data experts.

for loop is terminated by semicolon... why????

void Graphic::clearArea(int _x1,int _y1,int _x2,int _y2)
{
int i,j;
int x = whereX();
int y = whereY();
gotoxy(_x1,_y1);
for(j = _y1; j<=_y2 ; j++)
{
for(i = _x1;i<=_x2;i++)
{
gotoxy(i,j);
cout<<(" ");
}
}; // why this for loop is termineted by semicolon???????
gotoxy(x,y);
}
Sep 3 '09 #1
6 5265
donbock
2,426 Expert 2GB
What makes you think the for loop is terminated by a semicolon?

Where did you find this code?
Sep 3 '09 #2
JosAH
11,448 Expert 8TB
@singharchi
Because the author of that snippet of code didn't know the C++ language syntax; i.e. there is an empty statement there.

kind regards,

Jos
Sep 3 '09 #3
kkrish
3
Hi,

Might be he is confused teh code is runing without any syntax error, It is because its a semicolon that represent end of line nothing else.

You can put like this also

void test()
{
;;
;;;
}

here would not be any error, because of semicolon.
Sep 4 '09 #4
JosAH
11,448 Expert 8TB
@kkrish
It doesn't have anything to do with an end of line: a semicolon by itself is simply the end of an empty statement. e.g. the following is fine:

Expand|Select|Wrap|Line Numbers
  1. int x= 40;
  2. x= x+1;;;;;;;;;;;;x= x+1;
  3.  
kind regards,

Jos
Sep 4 '09 #5
kkrish
3
Hi,

Yes, thats true and the same I was trying to convey
Sep 7 '09 #6
donbock
2,426 Expert 2GB
  • End-of-line character is newline.
  • End-of-statement character for the preprocessor is newline; except when it is escaped.
  • End-of-statement character for the compiler is semicolon; except when it isn't.
Newline is just another whitespace character to the compiler. It has no special significance ... except to terminate "//" comments.

Semicolon has other uses by the compiler; for example, it is used to separate the clauses in a for statement.

Some compiler statements are terminated by something other than semicolon; for example, the control flow statements if...else if...else, switch, for, while. Notice the control flow statement do...while is terminated by a semicolon.

This post may be confusing, but you shouldn't find it misleading.
Sep 7 '09 #7

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

Similar topics

43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
12
by: chy1013m1 | last post by:
char *testCharArray = { "one", "two", "three", "four", "five", "six", NULL, };
14
by: Jan Schmidt | last post by:
Hi, in a nested do-while-loop structure I would like to "continue" the outer loop. With goto this should be no problem in while-loops. However, for do-while I cannot get it to work (without a...
5
by: hprYeV | last post by:
I have done a reasonable amount of programming in C++, but the other day I was talking to someone after a lecture in a course on Java who said that they had not been used to the syntax of the Java...
11
by: Rene | last post by:
Quick question, what is the point for forcing the semicolon at the end of the while statement? See example below: x = 0; do { x = x + 1; }while (x < 3); What's the point of having the...
11
by: Dan Upton | last post by:
This might be more information than necessary, but it's the best way I can think of to describe the question without being too vague. The task: I have a list of processes (well, strings to...
0
by: Gary Herron | last post by:
Dan Upton wrote: Yes. Create a list of keys, and loop through it: pids = procs_dict.keys() for pid in pids: if procs_dict.poll() != None # do the counter updates del procs_dict Then the...
2
by: singharchi | last post by:
void Graphic::goRight(void) { int x; int y; x = whereX(); y = whereY(); gotoxy(x+1,y); };
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: 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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.