Examples of $SELECT()

Example:

    GTM> F i=3:-1:0 W !,$S(i=1:"here",i=2:"come",i=3: "Watson")
    Watson
    come
    here
    %GTM-E-SELECTFALSE, No argument to $SELECT was true
    GTM>
    

This loop uses $SELECT() to WRITE a series of strings. Because there is no true argument on the fourth iteration, when i=0, $SELECT() produces an error.

Example:

    SET name=$S(sex="M":"Mr. ",sex="F":"Ms. ",1:"")_name
    

This example uses $SELECT() to add a prefix to the name based on a sex code held in the variable sex. Notice that the default handles the case of a missing or incorrect code.

Example:

    IF $S(x=+x:x,x="":0,"JANAPRJULOCT"[x:1,1:0) D THING
    

This uses $SELECT() to perform complex logic as the truth-valued expression argument to an IF command.