if-expressions

David B. Held dheld at codelogicconsulting.com
Mon May 28 01:06:27 PDT 2007


Bent Rasmussen wrote:
> [...]
> int lim(int x, int a, int b)
> {
>    return if (x < a)
>        a
>    else if (x > b)
>        b
>    else
>        x;
> }
> [...]

The advantage of having a statement-form of 'if' is that it creates a 
scope (expressions never create a scope).  Also, if allows you declare a 
variable in the condition, which is also not possible in expressions. 
See if your other languages can do that. ;)

Dave



More information about the Digitalmars-d mailing list