Question: I'm having a problem with my switch statement, sorry if this is trivial, I'm very new! At the switch statement I'm getting the error :

> 
> Syntax error on tokens, Label expected instead.
> 
> 
> 

At each of the cases I'm getting the error :

> 
> Syntax error on token "case", assert expected
> 
> 
> 

Both `productNumber` and `numberOfProduct` are type int input by the user. `total` and `currentTotal` are type `double`.

```
Switch (productNumber) //problem occurs here, at the switch statement and at each case
{
    case 1:
        currentTotal = numberOfProduct * 2.98;
        total += currentTotal;
        break;

    case 2:
        currentTotal = numberOfProduct * 4.50;
        total += currentTotal;
        break;

    case 3:
        currentTotal = numberOfProduct * 9.98;
        total += currentTotal;
        break;

    case 4://
        currentTotal = numberOfProduct * 4.49;
        total += currentTotal;
        break;

    case 5:
        currentTotal = numberOfProduct * 6.87;
        total += currentTotal;
        break;

    default:
        System.out.println("The number entered is not a known product number. Known product numbers are 1, 2, 3, 4, and 5.");
        --count;
}

```

Answer: 
You should use `ifelse`:

```
transform(data1,
          mutation = ifelse (genotype == "B3",  "wt",
          ifelse (genotype %in% c("ein9","ein194"),
                  "phyB", "hy2")))

#      internode_length treatment genotype mutation
# 1           98.165       sun       B3       wt
# 2          116.633       sun       B3       wt
# 3          103.474       sun     ein9     phyB
# 4          120.683       sun       B3       wt
# 5          109.128       sun   ein194     phyB
# 6          129.076       sun       A2      hy2

```
A data.table alternative.

toy data

```
#  internode_length treatment genotype
#            98.165       sun       B3
#           116.633       sun       B3
#           103.474       sun       B3
#           120.683       sun       B3
#           109.128       sun       B3
#           129.076       sun       B3
#           129.076       sun     ein9
#           129.076       sun   ein194
#           129.076       sun       XY

```

the code

```
library(data.table)
mydata[, new_col := ifelse(genotype == "B3", "wt",
                           ifelse(genotype %in% c("ein9", "ein194"), "phyB",
                                  "hy2")
)]
mydata

#    internode_length treatment genotype new_col
# 1:           98.165       sun       B3      wt
# 2:          116.633       sun       B3      wt
# 3:          103.474       sun       B3      wt
# 4:          120.683       sun       B3      wt
# 5:          109.128       sun       B3      wt
# 6:          129.076       sun       B3      wt
# 7:          129.076       sun     ein9    phyB
# 8:          129.076       sun   ein194    phyB
# 9:          129.076       sun       XY     hy2

```