Re:if..then..else and semicolons
In article <31e57f12.18148...@news.demon.co.uk>,
k...@itworks.demon.co.uk (Keith Edmunds) wrote:
Quote
>Is the "no semicolon before 'else'" rule confusing?
>Consider:
>if a = b then
> if c = d then
> x := y
>else
> n := m;
>Written with the indentation I've used, it's clear that I mean the else to
>refer to the first if (the 'a = b' one). However, the compiler - correctly -
>interprets the else as belonging to the 'c = d' if. Putting a semicolon
>after 'x = y' merely causes the compiler to complain that semicolons are not
>allowed before an "else" clause. Admittedly recoding the first two lines as
>"if a = b and c = d" is a work around, but is there a syntactically correct
>way of expressing which "if" the "else" belongs to?
Formatting and white space are for your understanding of the code not the
compiler's. It can take a rather amorphous mess and compile it like it's
written.
I usually sprinkle in a few extra Begin..End pairs in places where the syntax
can be a little ambigiuos(sp?). Nested If..Then..Else statements can be very
confusing without some sort of formatting discipline.
if a = b then
Begin
if c = d then
x := y
else
n := m;
End;
-----------------------------------------------
Mike Chapin
Powder River
mcha...@vcn.com
http://www.vcn.com/server/netizens/mchapin/first.html
Gillette, WY
Not the end of the earth but you can see it from
there.
-----------------------------------------------