Probably clearer, but I grew up learning that if you have more than 2
conditions, better to use a switch/case since it doesn't process the
whole condition, it stops when the answer if found.
if/elsif/elseif/elseif/elseif/elseif/else is bad practive! Every little
bit of processing I save helps :D
On 3/10/2010 4:16 PM, valdhor wrote:
Probably. But that's not what he asked for ;-}
--- In [email protected]
<mailto:flexcoders%40yahoogroups.com>, Richard Rodseth <rrods...@...>
wrote:
>
> That's very creative! But I think an if statement would be clearer...
>
> On Wed, Mar 10, 2010 at 6:00 AM, valdhor <valdhorli...@...>wrote:
>
> >
> >
> > Yes. You need to change the expression you are switching on...
> >
> > switch(true)
> >
> > {
> > case age >= 0 && age <= 4:
> > ageGroup = 1;
> > break;
> > }
> >
> >
> > The reason for this: Your case expression returns a true or false
value.
> > This does not match the expression in the switch so change the
expression in
> > the switch to reflect what will be returned in the case expression.
> >
> > HTH.
> >
> >
> > Steve
> >
> >
> >
> > --- In [email protected]
<mailto:flexcoders%40yahoogroups.com>, Wally Kolcz <wkolcz@> wrote:
> > >
> > > Is there a way to check for a range of conditions inside a case of a
> > > switch case? I want to so something like this:
> > >
> > > switfch(age){
> > > case (age >= 0 && age <= 4):
> > > ageGroup = 1;
> > > break;
> > > ...
> > > }
> > >
> >
> >
>