3 ms·
The requirement that braces be on the same line is a consequence of the semicolon insertion that the compiler performs. This is also why the error messages conf
by joeblubaugh 9y ago
The requirement that braces be on the same line is a consequence of the semicolon insertion that the compiler performs. This is also why the error messages confusing when the brace is on the next line.
Because a semicolon is inserted whenever the parser encounters an identifer or a token that's not in a special restricted set that includes ( and {, you end up with a semicolon inserted between a control flow statement and the bracket.
I suppose the grammar could have been modified to require that control statements include parens, or that the bracket become part of the control statement, but that's also kind of ugly ...