On Thu, 30 Jan 2003 10:48 am, Gavin Sinclair wrote:
> Now *that* is surprising!  I assumed that the braceless (one-line)
> version of "if" (and other control statements) was a typographical
> shortcut only.
>
> You learn something every day...

I know this isn't a C discussion list, but I just had to point this out - it's 
not just a typographical shortcut, it's an important part of the syntax. 
Without it, you couldn't do an 'else if':

The 'if' statement in C simply uses the next 'statement' for its content. By 
putting braces around it, you can make multiple lines into one 'statement' 
for the purposes of this. This logic is also how the else if in C works - 
there is no 'else if' explicitly defined in its syntax, like Ruby's elsif, 
but if you do this:
if (x)
{
	...
}
else if (y)
{
	...
}
The else is taking the next 'statement' as its content, which is in this case 
the second 'if'! The exact Ruby equivalent would be:
if x
	...
else
	if y
		...
	end
end
But you don't even notice that because of the syntax rules.

Tim Bates
-- 
tim / bates.id.au