Language Elements and Reference:xpplrm

Grouping expressions Foundation

Parentheses are also used to group expressions. The expressions may be a comma separated list on a single program line which are treated as a single expression. The result of an expression list is the value of the last expression in the list. The following program lines are valid:

LOCAL a:= 10, b:= 10, c:= 10, d := 10 
LOCAL nResult 

nResult := (a+=1, b/=2, c*=3, d-=4) 

? nResult                       // result:  6 
? a                             // result: 11 
? b                             // result:  5 
? c                             // result: 30 
? d                             // result:  6 

Several expressions can also be combined into one expression using parentheses in calls to statements and commands. This allows several expressions to be executed when only one argument can be specified. Examples are shown in the following program code:

LOCAL a:= 0, b := 0, c := 0, nSum := 0 

IF (++a, .F.) 
ELSEIF (++a, .F.) 
ELSEIF (++a, .F.) 
ELSEIF (++a, .F.) 
ELSE 
   ? a                          // result: 4 
ENDIF 

FOR i:=(++b, 1) TO (++c, 10) 
   nSum += i 
NEXT 

? b                             // result:  1 
? c                             // result: 11 

The example tests the IF...ENDIF branch and the FOR...NEXTloop using counter variables. The counter variables are incremented within the expression list and the result of each expression list (the last value) is evaluated by the statement.

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.