Parenthesis around if/for/while condition is not necessary

user1234 user1234 at 12.nl
Sat Jun 23 04:45:07 UTC 2018


On Saturday, 23 June 2018 at 01:27:30 UTC, aedt wrote:
> for line in stdin.lines() {}
>
> if condition {}
>
> while condition {}
>
> for init; condition; op {}
>
>
> What's the rationale of keeping the requirement that the 
> condition of if/for/while must be wrapped with a parenthesis 
> (other than keeping parser simple)? Modern languages have 
> already dropped this requirement (i.e. Rust, Nim) and I don't 
> see any reason not to do so.

There is this case that requires parens:

     if a && b c;

Is there a missing && or not ? It seems obvious for a human but 
compiler parsers are "apparatchiks", i.e rules are rules. That 
being said this would work by allowing parens for disambiguation.


More information about the Digitalmars-d mailing list