Rant after trying Rust a bit
jmh530 via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jul 22 14:36:56 PDT 2015
On Wednesday, 22 July 2015 at 20:43:04 UTC, simendsjo wrote:
> When "everything" is an expressions, you can write things like
> auto a = if(e) c else d;
>
> In D you have to write
> type a = invalid_value;
> if(e) a = c;
> else a = d;
> assert(a != invalid_value);
>
I prefer this example from one of the various Rust tutorials
let foo = if x == 5 {
"five"
}
else if x == 6 {
"six"
}
else {
"neither"
}
You're basically using a conditional expression as an rvalue. You
can do the same thing with a { } block.
More information about the Digitalmars-d
mailing list