Switch Case Statement

Use a switch/case statement to make sure your variables satisfy specific constraints

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
\begin{switch}
 
  \begin{case}{<condition 1>}
    <variable definitions>
  \end{case}
 
  \begin{case}{<condition 2>}
    <variable definitions>
  \end{case}
 
  ...
 
  \begin{default}
    <variable definitions>
  \end{default}
 
\end{switch}

Every variable in a switch environment must have a default definition, but not a definition for every
single case environment. (see example below)

There is no limitation on how many case environments you can use inside a switch environment. The default
environment though is obligatory!

You can use switch/case statements globally and on question level.

Never use switch/case statements in combination with \randadjustIf. It is meant as an alternative.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
\begin{variables}
  \randint{a}{1}{5}
  \function{f0}{10*a}
 
  \begin{switch}
    \begin{case}{a>3}
      \number{c}{3}
      \randrat{d}{1}{2}{3}{7}
      \drawFromSet{m}{1,2,3}
      \function{f}{2*a}
      \derivative{g}{3x^2+sqrt(x)}{x}
      \substitute{h}{sqrt(y)}{y}{g}
      \string{s}{case 1}
    \end{case}
 
    \begin{case}{a=3}
      \number{c}{5}
    \end{case}
 
    \begin{default}
      \randint{c}{1}{10}
      \randrat{d}{-2}{-1}{3}{7}
      \drawFromSet{m}{-1,-2,-3}
      \function{f}{-2*a}        
      \derivative{g}{-3x^2+sqrt(x)}{x}  
      \substitute{h}{sqrt(y)}{y}{g}
      \string{s}{default case}
    \end{default}
 
  \end{switch}
 
\end{variables}