title: Re-execute while loop after completion handler has been returned
body: <p>I have a while loop i wish to keep executing if the returned number is 0. The problem is currently have is that the loop never stops since it doesnt wait for the completion handler to return its results (which takes a couple seconds). How can i only re execute the while loop after the if statement has been completed? </p>
  
  <p><strong>while loop</strong></p>
  
  <pre><code>var empty = true
      override func viewDidLoad() {
              repeat {
          str = iFunctions.generateRandomStringWithLengthOf(4) as String
                  iFunctions.getServerData(str){(msg)
                      in
                      if (msg &gt; 0){
                          self.empty = false
                          print("not empty")
                      }
                      else{
                          print("empty")
                      }
                      self.count = msg!
                      print(self.count)
  
                  }
              } while(empty)
          }
  </code></pre>
  
  <p><strong>function</strong></p>
  
  <pre><code>func getServerData(q: String, completionHandler: (Int?) -&gt; ()) -&gt; () {
          let params = [
              "term": q
          ]
          Alamofire.request(.GET, "URL", parameters: params)
              .responseJSON { response in
                  if response.result.error == nil {
                      let json = JSON(response.result.value!)
                      //add data to struct
                      completionHandler(json["results"].count)
                  }
          }
  
      }
  </code></pre>