title: When to use forEach(_:) instead of for in?
body: <p>As documented in both <a href="https://developer.apple.com/documentation/swift/array/1689783-foreach" rel="noreferrer">Array</a> and <a href="https://developer.apple.com/documentation/swift/dictionary/1689593-foreach" rel="noreferrer">Dictionary</a> <code>forEach(_:)</code> Instance methods:</p>
  
  <blockquote>
    <p>Calls the given closure on each element in the <strong>sequence</strong> in the same
    order as a for-in loop.</p>
  </blockquote>
  
  <p>Nevertheless, adapted from <a href="https://developer.apple.com/documentation/swift/sequence" rel="noreferrer">Sequence Overview</a>:</p>
  
  <blockquote>
    <p>A sequence is a list of values that you can step through one at a
    time. <em>The most common way</em> to iterate over the elements of a sequence
    is to use a <strong>for-in loop</strong>.</p>
  </blockquote>
  
  <p>Implying that iterating sequence by <code>forEach(_:)</code> or <code>for in</code>:</p>
  
  <pre><code>let closedRange = 1...3
  
  for element in closedRange { print(element) } // 1 2 3
  
  closedRange.forEach { print($0) } // 1 2 3
  </code></pre>
  
  <p>Or (Array):</p>
  
  <pre><code>let array = [1, 2, 3]
  
  for element in array { print(element) } // 1 2 3
  
  array.forEach { print($0) } // 1 2 3
  </code></pre>
  
  <p>Would gives the same output.</p>
  
  <p>Why <code>forEach(_:)</code> even exist? i.e what is the benefit of using it instead of the <code>for in</code> loop? would they be the same from performance point view?</p>
  
  <p>As an assumption, it could be a syntactic sugar especially when working with <em>functional programming</em>.</p>