title: Exit iteration of for loop Swift iOS
body: <p>I have a function with a for loop inside of it: </p>
  
  <pre><code>func example() {
    // create tasks
    for link in links {
      let currIndex = links.indexOf(link)
  
      if let im = story_cache?.objectForKey(link) as? UIImage {
        if ((currIndex != nil) &amp;&amp; (currIndex &lt; content.count)) {
          if (content[currIndex!].resource_type == "image") {
            content[currIndex!].image = im
            return
          }
        }
      } else {
        if ((currIndex != nil) &amp;&amp; (currIndex &lt; content.count)) {
          if (content[currIndex!].resource_type == "video") {
            let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
            let documentsDirectory : NSString = paths[0]
            let appFile = documentsDirectory.stringByAppendingPathComponent(content[currIndex!].id! + ".mov")
            let local_URL = NSURL(fileURLWithPath: appFile)
            if let cached_URL = story_cache?.objectForKey(local_URL) as? NSURL {
              content[currIndex!].videoURL = cached_URL
              return
            }
          }
        }
      }
  
      let dltask = session.dataTaskWithURL(link, completionHandler: { (data, response, error) in  
        // MORE CODE.....
      })
    }
  }
  </code></pre>
  
  <p>Basically what I wanna achieve is that if we reach any of the <code>return</code> statements the code finishes executing for this particular <code>link</code> in the loop, and the loop moves on to the next link. If NONE of the return statements are reached, I want the <code>dltask</code> to be executed. I could achieve this using a bunch of else statements but I think that would make the code quite messy. Am I doing this right with using <code>return</code>?</p>