0

This piece of code does not work.

match ugly[i] {
    ugly[t2]*2 => t2+=1,
    ugly[t3]*3 => t3+=1,
    ugly[t5]*5 => t5+=1,
    _ => panic("no possible")
}
^ expected one of `=>`, `@`, `if`, or `|`

What I want is:

if ugly[i]==ugly[t2]*2 {
    t2+=1;
} else if ugly[i]==ugly[t3]*3 {
    t3+=1
} else {
    t5+=1
}

Can I do the same thing with match?

Tokubara
  • 392
  • 3
  • 13
  • No, this can't be done elegantly with `match`. But it smells a bit of a rather "unrusty" design. Perhaps if you could elaborate on the larger problem that you're trying to model with this switching statement, someone can propose a more idiomatic solution? – eggyal Oct 23 '22 at 13:40

0 Answers0