if-expressions
Leandro Lucarella
llucax at gmail.com
Thu May 31 08:34:44 PDT 2007
Chris Nicholson-Sauls, el 28 de mayo a las 04:04 me escribiste:
> Bent Rasmussen wrote:
> >I've been away from D for quite a while, but am anxious to get back and use the new features.
> >Reading the newsgroup to catch up a little, I remembered a feature of another language (haXe) I've been using for some light-weight work. It has the nice property that
> >`if´ is an expression. So I was wondering if this would be nice in D as well...
> >int lim(int x, int a, int b)
> >{
> > return if (x < a)
> > a
> > else if (x > b)
> > b
> > else
> > x;
> >}
>
> Or Ruby:
> # return if x < a then a
> # elsif x > b then b
> # else x
> # end
On Python (>= 2.5):
return a if x < a else \
b if x > b else x
--
LUCA - Leandro Lucarella - Usando Debian GNU/Linux Sid - GNU Generation
------------------------------------------------------------------------
E-Mail / JID: luca at lugmen.org.ar
GPG Fingerprint: D9E1 4545 0F4B 7928 E82C 375D 4B02 0FE0 B08B 4FB2
GPG Key: gpg --keyserver pks.lugmen.org.ar --recv-keys B08B4FB2
------------------------------------------------------------------------
- i bet microsoft's developers were on diet when they had to do win95
- microsoft has developers?
More information about the Digitalmars-d
mailing list