-1

I want to ask if the generated random Number is 1 or 13 or 25. I cut ask something like:

if randomNumber == (1) || if randomNumber == (13) || if randomNumber == (25)

and that's works but its way to much code. I try to minimize my code.

I did try something like this: if randomNumber == (1 || 13 || 25) but this didn't worked.

  • 4
    Does this answer your question? [How to compare one value against multiple values - Swift](https://stackoverflow.com/questions/32750139/how-to-compare-one-value-against-multiple-values-swift) – user3486184 Jul 31 '20 at 20:35

1 Answers1

0

You can convert them to a simple collection like an array or something and use its methods like:

if [1, 13, 25].contains(randomNumber)

More generally:

if (<#myArray#>.contains { <#condition#> }

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278