Re: switch vs elseif

From: Date: Mon, 12 Jan 2009 22:07:26 +0000
Subject: Re: switch vs elseif
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-286177@lists.php.net to get a copy of this message
On Mon, 2009-01-12 at 16:49 -0500, tedd wrote: > At 3:32 PM -0500 1/12/09, Robert Cummings wrote: > >One has to wonder about the readability of the case version though since > >one may not notice immediately the missing break statement. > > > >Cheers, > >Rob. > > Yes, but that's because of the way you wrote it -- consider this: > > <?php > switch( $foo ) > { > case 0: > // something > break; > > case 2: > case 3: > // something else > // something elser > break; > > default: > // something defaulty > } > ?> > > If you group the case's together, then there's no problem > understanding what happens in case 2 or 3. > > Cheers, > > tedd > -- > ------- > http://sperling.com > http://ancientstones.com > http://earthstones.com > I'd go further and enclose the code meant to execute in each case inside braces. Won't make a difference to the outcome of the code, but for some code editors (KATE for example), it helps to be able to close blocks of code so that it is hidden from view. DreamWeaver fans are missing out on this still I believe. Ash www.ashleysheridan.co.uk

« previous php.general (#286177) next »