select ifs, pick ifs
These two functions act like a cascaded arrangement of multiple select if resp. pick if function calls.
The first parameter contains the default value. Following this, the even-numbered parameters take boolean expressions, for example from
comparisons. If the outcome is true, then the value specified in the parameter is taken over, otherwise the next boolean expression wil be checked.
If all boolean expressions were false, then the defalt value will be returned.
select will calculate all function parameters
pick will calculate the 2nd function parameter followed by the 3rd parameter if true, otherwise it will calculate the 4th parameter, and so forth.
Long story short, only the parameter values needed will be calculated and this save a lot of processing time especialy for heavy expressions.
Indirect parameter passing is disabled
3, 5, 7, etc.
No. | Type | Description |
---|---|---|
1 input |
all types | Default value Applicable to select ifs: This value will be returned if all boolean values provided in the even-numbered function paramters are false. |
Alt. 1 code |
expression :string |
Default expression Applicable to pick ifs: This expression will be calculated and the value returned if all boolean values provided in the even-numbered function paramters are false. |
2, 4, ... input |
boolean | Boolean value Applicable to select ifs: This value is true, then the value in the next function parameter will be returned. |
Alt. 2, 4, ... code |
expression :string |
Boolean expression Applicable to pick if: If this expression calculated returns true, then the expression in the next function parameter will be calculated and the value returned. |
3, 5, ... input |
all types | Selected value if true Applicable to select ifs: This value will be returned if true is provided in the previous function parameter. |
Alt. 3, 5, ... code |
expression :string |
Selected expression if true Applicable to pick if: This expression will be calculated and returned if true is provided in the previous function parameter. |
Type | Description |
---|---|
all types | Selected value |
echo("Demonstrate 'select ifs':");
a[] = 1; b[] = 2; c[] = 3;
x[] = select ifs( echo("Others "), (a[]++=0), echo("1st "), (b[]++ = 2), echo("2nd "), (c[]++ = 3), echo("3rd ") );
// All parameter will be calculated.
echo("a..c[] = ", a[], " ", b[], " ", c[],". Result is ", x[] );
echo(new line, "Demonstrate 'pick ifs':");
a[] = 1; b[] = 2; c[] = 3;
x[] = pick ifs( echo("Others "), (a[]++=0), echo("1st "), (b[]++ = 2), echo("2nd "), (c[]++ = 3), echo("3rd ") );
// The first two conditions will be calculated as well as 'echo("2nd ")'.
echo("a..c[] = ", a[], " ", b[], " ", c[],". Result is ", x[] );
Demonstrate 'select ifs':
Others
1st
2nd
3rd
a..c[] = 2 3 4. Result is 2nd
Demonstrate 'pick ifs':
2nd
a..c[] = 2 3 3. Result is 2nd