Professional > Interview scripting > Writing interview scripts > Conditional actions > Select Case
 
Select Case
Select Case is a quick and easy way of defining conditional actions when the conditions are based on a question that can have only one value; that is a single-response categorical question, a numeric question, or a boolean question.
Syntax
Select Case Qname.Response.Value
  Case Response1
    Actions1
  Case Response2
    Actions2
  ...
  [Case Else
    ActionsN]
End Select
Parameters
Qname
The name of the question whose response controls the conditional actions.
Response1 and Response2
Responses to the question or, for numeric responses, expressions such as <value that group responses to the question.
Actions1 and Actions2
Are one or more statements to be executed if the question’s response matches the response for the current Case statement.
ActionsN
One or more statements to be executed for respondents who fail all the previous Case tests.
Example
Suppose your interview script contains the following questions:
BestColor "Which color scheme do you think suited
the product best?" categorical [1..1]
{
BluePink "Blue and pink" ,
RedYellow "Red and yellow" ,
YellowGreen "Yellow and green" ,
None "None were suitable"
};
Red "Why do you think red and yellow is effective?" text [1..];
Blue "Why do you think blue and pink is effective?" text [1..];
Green "Why do you think yellow and green is effective?"
    text [1..];
Having asked the Color question, you want to know why the respondent chose a particular color scheme. Because the question allows one response only, a Select Case statement makes this easy (compare this example with the one that uses If and ElseIf in If...Then...Else):
BestColor.Ask()
Select Case BestColor.Response.Value
Case {RedYellow}
Red.Ask()
Case{BluePink}
Blue.Ask()
Case {YellowGreen}
Green.Ask()
End Select
The Select Case statement tells the interviewing program to check which color was chosen. The Case statements define the possible responses and the actions that are to be taken for each one. Once a respondent has satisfied a Case test and the actions for that test have been executed, all other Case tests are ignored and the respondent continues with the next statement after End Select. Respondents who do not satisfy any of the Case tests simply pass through this section of the routing script with no actions being taken. In the example, this is what happens for respondents who say that none of the color schemes was suitable.
Here is an example for a numeric question. Notice how the range 31 to 59 has been specified.
Age.Ask()
Select Case Age
Case < 30
Young.Ask()
Case 30 To 59
Middleaged.Ask()
Case Else
Old.Ask()
End Select
See also
Conditional actions