expression

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sat May 30 03:19:37 PDT 2009


Ellery Newcomer wrote:
> what is the purpose of the expression grammar
> 
> Expression:
> 	AssignExpression
> 	AssignExpression , Expression
> 
> ?
> 
> (emphasis on the comma)

To allow two expressions separated by a comma to be another expression. This is 
only useful if the expression before the last comma has side-effects of course, 
since its value isn't used. Such an expression returns the result of its 
right-hand side.
For example: (foo(), bar()) is an expression that calls foo(), then calls bar() 
and evaluates to the return value of bar().

This is mostly used in the increment clause of a for loop, like this:
     for (int i = 0; i < max; i++, someOtherCounter++)


More information about the Digitalmars-d-learn mailing list