General rule when not to write ;

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Wed May 19 13:46:55 UTC 2021


On Tuesday, 18 May 2021 at 16:27:13 UTC, Alain De Vos wrote:
> After each } i write a ;
> And let the compiler tell me it is an empty instruction.
> What are the general rules where ; is not needed after a }

This is a good question, I'm not sure I can provide a concise 
answer.

In general you don't need a ; after }

The ; is used to end a statement, but I don't know how to define 
that and distinguish it from an expression.

The {} create a block of code, usually they will contain 
statements, so it would be common to see ; inside.

The only real time I would expect a }; is when you're defining a 
lambda/delegate and assigning to a variable.

auto Foo = X;

If X is something that ends with } we will still expect a ; to 
end the statement.


More information about the Digitalmars-d-learn mailing list