select if, pick if
This function selects and returns the 2nd function parameter if the 1st parameter is 'true', otherwise the 3rd function parameter is returned.
select will calculate all function parameters.
pick will calculate the 1st parameter and then either the 2nd (if true) or 3rd function parameter (if false). In C/C++, the function works similar to
the following trinary operator: ? ... ? ... .
Indirect parameter passing is disabled
3
No. | Type | Description |
---|---|---|
1 input |
boolean | Boolean value |
2 input |
all types | Selected value if true This expression will be always calculated. It will be returned if 'true' is provided in the 1st function parameter. |
Alt. 2 code |
expression :string |
Selected expression if true Applicable to pick if: This expression will be calculated and the value returned if 'true' is provided in the 1st function parameter. Otherwise, calculating this parameter will be skipped. |
3 input |
all types | Selected value if false This expression will be always calculated. It will be returned if 'false' is provided in the 1st function parameter. |
Alt. 3 code |
expression :string |
Selected expression if false Applicable to pick if: This expression will be calculated and the value returned if 'false' is provided in the 1st function parameter. Otherwise, calculating this parameter will be skipped. |
Type | Description |
---|---|
all types | Selected value |
a[] = 1; b[] = 2;
echo("Function 'select if':");
print( select if( true, a[]++, b[]++ ) ); // Both a[] and b[] are incremented
echo( " a[] = ", a[], " b[] = ", b[] );
echo;
a[] = 1; b[] = 2;
echo("Function 'pick if':");
print( pick if( false, a[]++, b[]++ ) ); // Only b[] is incremented
echo( " a[] = ", a[], " b[] = ", b[] );
Function 'select if':
1 a[] = 2 b[] = 3
Function 'pick if':
2 a[] = 1 b[] = 3