"Comma (multi-statement)" documentation
Posted: 10 Mar 2020, 15:11
The following two aspects of the "Comma" may be implicit in it being listed in the documentation within the list of expression operators, but they're not obvious and maybe should be explicitly stated:
1/ the fact that the value (result) of a comma expression is the result of its leftmost expression. This is intuitively clear when the leftmost expression is an assignment as in even though it's (I assume) parsed as but not so intuitive otherwise, as in or in
2/ the fact that a comma expression is a single expression and can therefore be used without braces following an If or Else, as in In this regard, I believe this operator should be described in the documentation as "Comma (multi-expression)" rather than "... (multi-statement)" since the latter suggests that braces should be used in the above situation.
JB
1/ the fact that the value (result) of a comma expression is the result of its leftmost expression. This is intuitively clear when the leftmost expression is an assignment as in
Code: Select all
a := 1, b := 2, c := 3, d := 4
Code: Select all
a := (1, (b := (2, (c := (3, (d := 4))))))
Code: Select all
Return (False, a := 2, b := 3) ; a and b are ByRef parameters
Code: Select all
MsgBox, % (Func(a, b), ++a, ++b)
Code: Select all
If !a
b := 2, c := 3, d := 4
Else
b := 3, c := 4, d := 5
JB