From: Gavin Sinclair Date: 2003-01-30T09:18:17+09:00 Subject: Re: Local variables & blocks On Thursday, January 30, 2003, 11:13:45 AM, Paul wrote: > On Thu, Jan 30, 2003 at 08:35:01AM +0900, Gavin Sinclair wrote: >> The behaviour exhibited by that snippet always struck me as >> "surprising", coming from C-like languages where "if" introduces a new >> scope. > In C, "if" doesn't introduce a new scope; {} does: > void foo() { > int x = 1; > if(1) > int x = 2; // error: redeclaration of x > if(1) { > int x = 2; // okay; the outer x is hidden by this one > } > } 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...