<div dir="ltr"><div>Since Swift almost abolished the semi-colon as an end of statement marker, and Swift 3 is abolishing is in C-style for-loops, I thought I&#39;d suggest something else for it to do.</div><div><br></div><div>Swift 1.2 allowed developers to pack multiple if let bindings into one if let, using comma separators. This was well received as it removed the disliked &#39;pyramid of doom&#39; - lots of nested indented if statements.</div><div><br></div><div>I&#39;d like to propose using the semi-colon to pack if lets and regular ifs into one if. The format would essentially be:</div><div>if &lt;boolean expression&gt;; let x = x as? Foo; &lt;boolean expression&gt;; let y = x.&lt;property&gt;, z = y.&lt;property&gt; // and so on</div><div>{</div><div>  // closure which only happens if both expressions are true and all three bindings happen; note that the last two are comma-separated as they&#39;re both &#39;if let&#39;s.</div><div>}</div><div><br></div><div>There would only be one actual &#39;if&#39;. The semi-colon<br></div><div>This would also be applicable to guard and guard let. I&#39;ve had a number of occasions where I&#39;ve written multiple guard statements with identical else closures. I&#39;d like to avoid some of that duplicate code.</div><div><br></div><div>I realise that it&#39;s already possible to combine conditions and conditional bindings in one if, using the &#39;where&#39; keyword, but I don&#39;t think it&#39;s clear - certainly not as clear as when where filters for-in ranges or case statements.</div><div><br></div><div>For example: getting the first element from an array of optionals. Here&#39;s my sample trivial example:</div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span><span style="color:rgb(187,44,162)">var</span> array : [<span style="color:rgb(112,61,170)">Int</span>?] = []</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span><span style="color:rgb(187,44,162)">if</span> <span style="color:rgb(187,44,162)">let</span> x = array[<span style="color:rgb(39,42,216)">0</span>] <span style="color:rgb(187,44,162)">where</span> array.<span style="color:rgb(112,61,170)">count</span> &gt; <span style="color:rgb(39,42,216)">0</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span>{</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">                </span><span style="color:rgb(61,29,129)">print</span>(x)</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span>}</p></div><div>This code doesn&#39;t work. The array index is out of range. But there&#39;s no way I know of to rearrange the &#39;if&#39; to ensure the array isn&#39;t empty before binding to the first element - the developer has to write a nested if statement.</div><div><br></div><div>My suggested syntax would present the if like this:</div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span><span style="color:rgb(187,44,162)">if</span> array.count &gt; <span style="color:rgb(39,42,216)">0</span>;</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="white-space:pre">        </span><span style="white-space:pre">        </span><span style="color:rgb(187,44,162)">let</span> x = array[<span style="color:rgb(39,42,216)">0</span>]</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span>{</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">                </span>print(x)</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span class="" style="white-space:pre">        </span>}</p></div><div><br></div><div>The semi-colon would read as &#39;and&#39; in the same way the comma does in a multiple if let or &amp;&amp; does in an if; it allows the developer to alternate between boolean expressions and conditional bindings. (The downside here is that three distinct punctuation symbols are all essentially used to mean the same thing.)</div><div><br></div><div>Is this worthy of discussion?</div><div><br></div></div>