Group Group Group Group Group Group Group Group Group

Make an arithmetic sequence in a if statement

I want to make an arithmetic sequence in a if statement using the contain framework. So instead of writing the in statement like

 if [ 30, 60, 90,120].contains(score) {
            print(“Winner”)
        }

I want to write a equation that has the arithmetic sequence goes on for 10 times. So in the sequence it should 30,60,90,120,150,180,210,240,270,300. I would think there is a way to write the if statement to do this.

You’re looking for “stride”!

https://developer.apple.com/documentation/swift/1641347-stride
https://developer.apple.com/documentation/swift/1641185-stride

Video example here at 4:40
https://www.raywenderlich.com/5429279-programming-in-swift-functions-and-types/lessons/4

You might want to try the remainder operator:

if score % 30 == 0 {

or the isMultiple(of:) method:

if score.isMultiple(of: 30) {