Re: Simple question regarding the use of ;




"Stephen Sprunk" <stephen@xxxxxxxxxx> wrote in message
news:MgV6l.4136$jZ1.316@xxxxxxxxxxxxxxxxxxxxxxx
Andrew wrote:
Hello,
I have been doing some microprocessor programming, and I have run into
some variations in the way people use the semi-colon. Please tell me
the difference between these two statements.

1. while(1)
{
value = read_adc(1);
}

2. while(1)
{
value = read_adc(1);
};

Is the semi-colon on statement 2 doing anything? The code seems to

A semicolon terminates a simple statement, as in "value = read_adc(1);". A
compound statement is enclosed by '{' and '}' and contains zero or more
simple or compound statement; there is no need for a ';' to terminate a
compound statement, because the '}' does that.

I'm not sure that was the reason. Otherwise you could say the last (simple) statement in a {...} block doesn't need a terminating semicolon because the } does that job too. Then the semicolon reverts to a statement separator.

I think that {...} statements not needing a semicolon terminator is just
another oddity of C.

--
Bartc

.



Relevant Pages

  • Re: DeLillo: comma
    ... colon might be too formal? ... Many authors avoid the semi-colon as if it was smallpox infested key ... A Swedish friend describes the semicolon as "ett njutningsmedel för ...
    (alt.usage.english)
  • Re: Print with no line feed
    ... what my help file says: ... Multiple expressions can be separated with either a space or a semicolon. ... I don't think it's at all clear that the semi-colon accomplishes what the OP ... you will see a semi-colon after the Print statement ...
    (microsoft.public.excel.programming)
  • Re: Languages (moved from another thread)
    ... I am referring to VB 2010 in which the line end/line continue has changed from the nice easy Enter ends, Underscore continues to semicolon ends, Send continues. ... they have different key words and different syntax. ... once have I had to terminate a statement with a semi-colon. ... I know for a fact that VB.Net wipes the floor with VB6. ...
    (comp.databases.pick)
  • Re: passing arguments
    ... The latter, it is my understanding, is the reason he posts as Dr. John instead of just John. ... When asked to provide "typical" code where the lack of a semicolon caused an error when the semicolon removed it, I got one example and Richard couldn't remember the full context. ... there are places that adding a semi-colon to the end of a line will cause errors where the lack of that semi-colon isn't an error. ...
    (comp.lang.javascript)
  • Re: Simple question regarding the use of ;
    ... I have been doing some microprocessor programming, ... some variations in the way people use the semi-colon. ... A compound statement is enclosed by '' and contains zero or more simple or compound statement; there is no need for a ';' to terminate a compound statement, ...
    (comp.lang.c)