choose( key, choice1, choiceN )
Evaluates the choice
argument at the given index
and returns the result.
See also: wherecontains()
Keyword  Type  Description 


Number (Integer) 
The onebased index that selects which choice argument to evaluate and return. 

Any Type 
The first of n possible expressions, where n must be >= 1. Only the selected value is evaluated. 

Any Type 
An unlimited number of expressions. 
Any Type
null
will be returned.Unlike most functions, choose does not evaluate all its arguments. First the index is evaluated, then the selected value arguments. The unchosen arguments are not evaluated. Use choose
to avoid calling potentially costly expressions whose results would be discarded.
You can experiment with this function in the test box below.
Test Input
Use expressions as the choice
arguments or as the index
argument.
choose(2,2+2,4/2,3^2)
returns 2
choose(weekday(today()),"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
returns the name of the day of the week
It can be useful to use the wherecontains
function in conjunction with choose
. Since wherecontains
returns a list, use the first result for the index
parameter.
1
2
3
4
5
6
choose(
wherecontains(ri!rating, {"Poor","Satisfactory","Excellent"})[1],
mod(rand() * 10, 5),
mod(rand() * 10, 5) + 4,
10  mod(rand() * 10, 2)
)