break's scope
Posted: 10 May 2009 17:28
I know I'm late to the party, as it has already been included on a new official release, but I have a question about break. It seems that the way it was done, break works for while as well as if, and I was just wondering if that was such a good idea.
Might be that I'm used to PHP (where break doesn't apply to if's) but I find this somewhat odd:
And I probably find it even more odd that if I had only used "break;" it only applied to the if, and so this was an endless loop...
Besides, maybe I'm not seeing the obvious, but why would you ever break from a if? Isn't it the same/easier to just close the bracket?
Any reason this was done that way, and not like PHP does it? Any other opinions as to which is better?
Might be that I'm used to PHP (where break doesn't apply to if's) but I find this somewhat odd:
Code: Select all
$i = 3;
while (1)
{
$i--;
if ($i == 0) { break 2; }
}Besides, maybe I'm not seeing the obvious, but why would you ever break from a if? Isn't it the same/easier to just close the bracket?
Any reason this was done that way, and not like PHP does it? Any other opinions as to which is better?