Hi Wolfgang,

PICK$ will select the nth item from the list that follows the n.

Consider          PICK$(n, "aaa", "bbb", "ccc", "ddd", "etc")

If n is 1 then PICK$ will return "aaa" because it is the 1st item in the list.  
If n is 5 then "etc" would be returned because it is the 5th item.  The 
parameters of PICK$ can be of any type: they will be coerced into strings.  
Expressions can be supplied, for example, dev$ & file$.
 
There is a particular problem that PICK$ may help us to solve.  Occasionally, 
we may want to iterate through a list of items.  If these items are strings, 
then we may well reach for a FOR loop and do something like . . .

FOR x$ = "aaa", "bbb", "ccc", "ddd", "etc" 

Unfortunately, this is not allowed.  The identifier for a FOR loop has to be 
numeric, either floating point or integer.  This leaves us with a problem: how 
to do the above? 
There is a way to do this.  A normal numeric FOR loop could be used, and then 
assign values to x$ depending on the FOR loop index, like this . . .

FOR n = 1 TO 5 
  SELect ON n = 1 : x$ = "aaa" : = 2 : x$ = "bbb" : = 3 : x$ = "ccc" : = 4 : x$ 
= "ddd" : = 5 : x$ = "etc"

This can also be done using PICK$ . . .

FOR n = 1 TO 5 
  X$ = PICK$(n, "aaa", "bbb", "ccc", "ddd", "etc")

Which version do you prefer?

The version using PICK$ may be more readable, but please bear in mind the 
following.  PICK$ will evaluate all of its parameters before deciding  which 
value to return, so, in terms of efficiency, this would not be the best choice. 
 If outright execution speed is top priority, then the Select version should be 
chosen.

What I like about PICK$ is the readability factor.  I use PICK$ in my own 
programs and can recommend it.

Michael
_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to