switch(n, a, b, c, ...)

Given a whole number 0, 1, 2, ... and a list of items, returns the nth item in the list (the first item is in position 0, the second in position 1, and so on).

 

For example,

 

$prime = switch(rint(5), 2, 3, 5, 7, 11)

 

sets $prime to a random choice from the first 5 primes.

 

switch(1, "red', 'green", "yellow") returns "green"

 

See Also:

List-based variables

Math and Logical Functions

rank

rint