develooper Front page | perl.perl6.language | Postings from July 2001

Re: if then else otherwise ...

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
July 30, 2001 20:37
Subject:
Re: if then else otherwise ...
Message ID:
20010729024339.P2983@blackrider
On Sat, Jul 28, 2001 at 04:34:46PM +0300, raptor wrote:
> if (cond)
> { }
> else {}
> otherwise {}
> 
> 
> i.e.
> if cond == 1  then  'then-block'
> if cond == 0  then  'else-block'
> if cond == -1  then  'otherwise-block'

Sounds like you need a switch, yes.  The cases where "cond" will
be 1, 0 and -1 is fairly rare in Perl and is pretty much limited
to cmp and <=>.

I'm curious to see examples of existing code which otherwise would
improve, but it really doesn't seem like there's much improvement
either way and you severely complicate the meaning of C<if( cond )>,
since it has to now fail on -1 if C<otherwise> exists.


PS  -1 is true, just to make sure that's clear.

-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
Hold on while I slip into something a little more naked.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About