Re: control structure question

From: Date: Thu, 25 Jul 2002 08:29:40 +0000
Subject: Re: control structure question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-109449@lists.php.net to get a copy of this message
On Tue, 23 Jul 2002, Javier Montserat wrote: > So refering back, i re-wrote the original example using the switch syntax... > > switch (true) { > case doStep1(): > case doStep2(): > case doStep3(): > error(); > break; > default: > valid(); > } > > Each case expressions is evaluated, until one of them evaluates to a value > equal (==) to the switch expression (in this case a boolean error flag). > > The error() code will only be called if one of the doStep() evaluates to > false. > > And the valid() code will only be evaluated if the switch reached the > default, which means that none of the above check returned false > > I think for this example the switch syntax is more elegant than using a > series of if() statements. That's pretty clever! miguel

« previous php.general (#109449) next »