Do you think if statement as expression would be nice to have in D?

user1234 user1234 at 12.de
Sat Jun 4 16:24:10 UTC 2022


On Saturday, 4 June 2022 at 16:15:26 UTC, Nick Treleaven wrote:
> On Saturday, 4 June 2022 at 11:35:41 UTC, user1234 wrote:
>> ```
>> const char = if (current < input.len)
>>             input[current]
>>         else
>>             break;
>> ```
>>
>> - So the `break` expression has a type ? And this type is 
>> compatible with the typê of `input[current]` ? wut ?
>
> Just like `throw` is an expression in D now. It's type is 
> noreturn, which implicitly converts to any type.

I think this does not give intuitively what char value will be: 
undefined, 0 ?
Well in this case a loop is exited and char is out of scope so 
that does not matter but what if char is a var owned by the loop 
outer scope.


More information about the Digitalmars-d mailing list