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

Empty Block require semicolon?

If I had some code, with several if-then-else clauses, one of them
containing an empty block, would I need a semi-colon in that block?
What effect would a semicolon have?

I ask because I have inherited some code that contains such a
construct, and I'm not sure if the blatant semicolon is required, or
was just thought to be required.
EX:

if (something1)
{
// code here;
}
else if (something2)
{
// code here;
}
else if (something3)
{
// nothing here but comments
// do I need a ";" here?
// if there is one here, what effect, if any, does it have?
// does it short-circuit anything?
}
else if (something4)
{
// code here;
}

Jun 22 '06 #1
3 2279
wh*************@gmail.com wrote:
If I had some code, with several if-then-else clauses, one of them
containing an empty block, would I need a semi-colon in that block?
No.
What effect would a semicolon have?
Different effect in different places. In an empty block it has no
effect.
I ask because I have inherited some code that contains such a
construct, and I'm not sure if the blatant semicolon is required, or
was just thought to be required.
EX:

if (something1)
{
// code here;
}
else if (something2)
{
// code here;
}
else if (something3)
{
// nothing here but comments
// do I need a ";" here?
No.
// if there is one here, what effect, if any, does it have?
None.
// does it short-circuit anything?
Huh?
}
else if (something4)
{
// code here;
}


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 22 '06 #2


wh*************@gmail.com wrote:
If I had some code, with several if-then-else clauses, one of them
containing an empty block, would I need a semi-colon in that block?
What effect would a semicolon have?

I ask because I have inherited some code that contains such a
construct, and I'm not sure if the blatant semicolon is required, or
was just thought to be required.

EX:

if (something1)
{
// code here;
}
else if (something2)
{
// code here;
}
else if (something3)
{
// nothing here but comments
// do I need a ";" here?
// if there is one here, what effect, if any, does it have?
// does it short-circuit anything?
}
else if (something4)
{
// code here;
}


no you don't need it. It is the end of an 'empty' statement that does
nothing. But some people put those in as
a kind of comment to clarify the block is meant to be empty , vs. that
the block accidentally had its code
deleted...

David

Jun 22 '06 #3
Thanks, Vic and Dave.

I was hoping that the semicolon was the source of a problem, but I
found the real culprit.
--
W

Jun 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
5
by: Ney André de Mello Zunino | last post by:
Hello. Running the following document through the W3C's validator, returns the error: "end tag for "body" which is not finished." <!-- Start of sample document --> <?xml version="1.0"...
2
by: autogoor | last post by:
The empty line that is inserted by most browsers between H1/H2/H3 heading tags and a following P block is very annoying and I would really like to get rid of it (without having to give up on using...
4
by: Jeronimo Bertran | last post by:
I have a multithreaded application that manipulates a Queue: protected Queue outputQueue; when I add elements to the queue I use a critical section private void Add(OutputRecord record) {...
10
by: Maksim Sipos | last post by:
Hello, I would like to have something like #ifdef VERSION_DEBUG #define DEBUG(x) DebugFnc(x) #end #ifdef VERSION_RELEASE #define DEBUG(x) <empty-statement> #end
5
by: Alfonso Morra | last post by:
I have the following data types: typedef union { long l ; double f; char* s ; void* p ; } Value ; typedef struct {
3
by: Suneeel | last post by:
Hi All, I'm having trouble with iterating through an STL map. Firstly, for an empty map, will map.begin() be equal to map.end()? If this is true, the program should not be entering the while...
2
by: talkaboutquality | last post by:
Need to define a macro as, say, #ifdef NEED_FUNCTION foo(x) #else #endif
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
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...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.