title: How to find the lowest number in an array?
body: <p>I am writing an algorithm to find the lowest number in an array however my print statement keeps saying that the lowest number is 0. I have the following: </p>
  
  <pre><code>var list = [5, 4, 3, 5, 2, 50, 8, 10, 300]
  
  func findMin(numbers: NSArray) {
  
      var minValue = numbers[0]
      var isSmallest: Bool
  
      for i in 0...numbers.count {
          isSmallest = true
          for j in 0...numbers.count {
              if i &gt; j {
                  isSmallest = false
              }
          }
  
          if isSmallest {
              minValue = i
          }
  
      }
      print("Smallest value in the list is \(minValue)")
  }
  
  findMin(numbers: list as NSArray)
  </code></pre>
  
  <p>My print statement returns as: </p>
  
  <pre><code>"Smallest value in the list is 0\n"
  </code></pre>
  
  <p>I feel like the algorithm is correct. Any ideas?</p>
  
  <p>EDIT: Answered my own question </p>
  
  <p>I was iterating over indices and not actual values. Thanks to one of the users in the comments. The correct code should be: </p>
  
  <pre><code>var list = [5, 4, 3, 5, 2, 50, 8, 10, 300]
  
  func findMin(numbers: NSArray) {
  
      var minValue = numbers[0]
      var isSmallest: Bool
  
      for i in list {
          isSmallest = true
          for j in list {
              if i &gt; j {
                  isSmallest = false
              }
           }
  
          if isSmallest {
              minValue = i
          }
  
      }
  
      print("Smallest value in the list is \(minValue)")
  }
  
  findMin(numbers: list as NSArray)
  </code></pre>