Question: I am trying to solve the task

> 
> Using a standard for-in loop add all odd numbers less than or equal to 100 to the oddNumbers array
> 
> 
> 

I tried the following: 

```
var oddNumbers = [Int]()
var numbt = 0
for newNumt in 0..<100 {
    var newNumt = numbt + 1; numbt += 2; oddNumbers.append(newNumt)
}

print(oddNumbers)

```

This results in:

> 
> 1,3,5,7,9,...199
> 
> 
> 

My question is: Why does it print numbers above 100 although I specify the range between 0 and <100?

Answer: 
> 
> Why does it print numbers above 100 although I specify the range between 0 and <100?
> 
> 
> 

Look again at your code:

```
for newNumt in 0..<100 {
    var newNumt = numbt + 1; numbt += 2; oddNumbers.append(newNumt)
}  

```

The `newNumt` used inside the loop is different from the loop variable; the `var newNumt` declares a new variable whose scope is the body of the loop, so it gets created and destroyed each time through the loop. Meanwhile, `numbt` is declared outside the loop, so it keeps being incremented by 2 each time through the loop.

I see that this is an old question, but none of the answers specifically address looping over odd numbers, so I'll add another. The `stride()` function that Luca Angeletti pointed to is the right way to go, but you can use it directly in a `for` loop like this:

```
for oddNumber in stride(from:1, to:100, by:2) {
    // your code here
}

```

`stride(from:,to:,by:)` creates a list of any strideable type up to but not including the `from:` parameter, in increments of the `by:` parameter, so in this case `oddNumber` starts at `1` and includes `3, 5, 7, 9...99`. If you want to *include* the upper limit, there's a `stride(from:,through:,by:)` form where the `through:` parameter is included.
For **Swift 4.2** 

```
extension Collection {
    func everyOther(_ body: (Element) -> Void) {
        let start = self.startIndex
        let end = self.endIndex

        var iter = start

        while iter != end {
            body(self[iter])

            let next = index(after: iter)
            if next == end { break }
            iter = index(after: next)
        }
    }
}

```

And then you can use it like this:

```
class OddsEvent: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        (1...900000).everyOther{ print($0) } //Even
        (0...100000).everyOther{ print($0) } //Odds

    }
}

```

This is more efficient than:  

**let oddNums = (0...100).filter { $0 % 2 == 1 }** or  

**let oddNums = Array(stride(from: 1, to: 100, by: 2))**  

because supports larger Collections 

Source: <https://developer.apple.com/videos/play/wwdc2018/229/>