title: Sequentially iterate through all the values in a loop and use they
body: <p>How can i use loop or may be without loop to <strong>Sequentially</strong> iterate through all the <strong>values</strong> and <strong>use they</strong>? My <strong>array</strong> in firebase have 5 items. Now I get this result <code>print("index - \(index)"</code>:</p>
  
  <pre><code>index - 0
  index - 1
  index - 0
  index - 1
  index - 2
  index - 0
  index - 1
  index - 2
  index - 3
  index - 0
  index - 1
  index - 2
  index - 3
  index - 4
  index - 0
  index - 1
  index - 2
  index - 3
  index - 4
  index - 5
  index - 0
  index - 1
  index - 2
  index - 3
  index - 4
  index - 5
  </code></pre>
  
  <p><strong>And</strong> <code>print("count - \(self.MyIndex.count)")</code>:</p>
  
  <pre><code>count - 1
  count - 2
  count - 3
  count - 4
  count - 5
  </code></pre>
  
  <p><strong>With my code</strong>:</p>
  
  <pre><code>func load() {
  
      firebaseRef = Database.database().reference(withPath: "MyFirebase")
  
      firebaseRef.observe(.value, with: { (snapshot) in
  
          DispatchQueue.main.async {
  
              for snap in snapshot.children {
  
                  let item = FirebaseIndex(snapshot: snap as! DataSnapshot)
  
                  self.MyIndex.append(item)
  
                  print("count - \(self.MyIndex.count)")
  
                  for index in 0...self.MyIndex.count {
  
                      print("index - \(index)"
  
                  }
              }
          }
      })
  }
  </code></pre>
  
  <p>What am I doing wrong? how do I get the correct <strong>indexes</strong> same as <strong>count</strong>?</p>