select / pick by value

Prev Next

Function Names

select by value, pick by value

Description

These two functions compare the value provided in the 1st function parameter with the 2nd function parameter. If the value in both function parameters are equal, then the value provided in the 3rd funtion parameter will be returned. If this is not the case, the 4th fuction parameter will be checked, and so on. If none of the values are matching, and the number of function parameters is even, then the last value is considered as default value and will be returned. In case the number of parameters is odd and no matches have been identified, then void value is returned.

Note: Special cases with incomplete number of function parameters
If only 1 function parameter is provided, then void value will be returned all times.
If only 2 function parameters are provided, then the last parameter will be returned all times.

Call as: procedure or function

Restrictions

Indirect parameter passing is enabled for 'select by value'.

Parameter count

Min. 1

Parameters

No.TypeDescription
1
input
valid types Selector value

The value provided in the 1st function parameter will be compared with the values in the even-numbered parameters.

2, 4, ...
input
boolean Value to match

Applicable to select ifs: This value will be compared with the 1st function parameter.

Alt. 2, 4, ...
code
expression
:string
Expression to match

Applicable to pick ifx: This expression will be calculated (as long no match has been found yet) and the value will be compared with the 1st function parameter.

3, 5, ...
input
boolean Value to select

Applicable to select ifs: This value will be returned if a match with the previous parameter applies.

Alt. 3, 5, ...
code
expression
:string
Expression to select

Applicable to pick ifx: This expression will be calculated and the value returned if a match with the previous parameter applies. Otherwise, the expression will not be calculated.

last (even number)
input
boolean Value to select

Applicable to select ifs: This is the default value to be returned if no matches have been identified.

Alt. last (even number)
code
expression
:string
Expression to select

Applicable to pick ifx: This is the default expression to be calculated and the value returned if no matches have been identified.

Return value

TypeDescription
all types Selected value

Examples


  a[] = Hund;

  echo("Demonstrate 'select by value':");
  // Note: All parameters are executed, i.e. printed out
  x[] = select by value( a[], print(Katze), print(Cat), print(Hund), print(Dog), print(Maus), print(Mouse) );
  echo(new line, "Result is ", x[] );

  echo("Demonstrate 'pick by value':");
  // Note: The calculated expressions will be printed out: Katze, Hund and Dog. No need to execute the other ones
  x[] = pick by value( a[], print(Katze), print(Cat), print(Hund), print(Dog), print(Maus), print(Mouse) );
  echo(new line, "Result is ", x[] );

Output

Demonstrate 'select by value':
KatzeCatHundDogMausMouse
Result is Dog
Demonstrate 'pick by value':
KatzeHundDog
Result is Dog
Try it yourself: Open LIB_Function_select_by_value.b4p in B4P_Examples.zip. Decompress before use.

See also

select ifs
pick ifs