title: How to construct the English alphabet using a loop in Swift
body: <p>How can I construct the English alphabet using a for loop, i.e. without writing all the characters manually?</p>
  <p>I normally do:</p>
  <pre><code>let alphabet = &quot;abcdefghijklmnopqrstuvwxyz&quot;
  </code></pre>
  <p>But I think there must be a more elegant way to achieve this. This can be easily done in <code>C</code> as <code>char</code>s are merely ASCII codes:</p>
  <pre><code>#include &lt;stdio.h&gt;
  int main() {
      char c;
      for (c = 'a'; c &lt;= 'z'; ++c)
          printf(&quot;%c&quot;, c);
      return 0;
  }
  
  </code></pre>
  <p>But since Swift supports Unicode, it is a little tricky. We can construct a <code>ClosedRange&lt;String&gt;</code> as in <code>let alphabet = &quot;a&quot;...&quot;z&quot;</code> which is helpful in comparing whether a character is between &quot;a&quot; and &quot;z&quot;, but I couldn't find an easy way to extract all possible values in a closed range.</p>