<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 10 Jun 2017, at 13:33, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">_Every_ addition to the basic syntax of the language is, by definition, high cost. The bar for additions to the standard library is already very high; the bar for additions to control flow syntax would be extraordinarily high.<br class=""><br class="">The proposed use case here is far from the original topic of repeat {} while, which is unique because the condition lexically follows the loop.</div><div class=""><br class=""></div><div class="">For those loops in Swift where it is possible to declare variables in the condition, these live in a magical middle scope that is intuitive to use but also an exception to the rule of thumb that scopes are surrounded by braces. As I wrote earlier, it is possible to manually create an analogous scope by surrounding any loop with do {}. Any addition to the language would have to be vastly superior to this currently possible alternative, and I seriously doubt it is possible to invent such a thing because anything shorter than the four letters in “do {}” would also obscure the existence of the middle scope being created.</div></div></blockquote><br class=""></div><div>The problem with nesting within do {} blocks is that it actually makes the problem worse; the main benefit of being able to declare the variables more conveniently is to eliminate common boiler-plate around loops. Creating them with a limited scope is a useful bonus (and further reduces clutter/name pollution).</div><div><br class=""></div><div>On the issue of tackling boilerplate, consider something like the following:</div><div><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><font face="Monaco" class="">// Remove the first 100+ units of items and store the names in an array</font></div><div><font face="Monaco" class="">var theNames:[String] = []</font></div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><font face="Monaco" class="">do {</font></div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><font face="Monaco" class="">var theTotal = 0</font></div></blockquote></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><font face="Monaco" class="">while let eachItem = theIterator.next() {</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>theNames.append(eachItem.name)</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>theTotal += eachItem.value</font></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if theTotal &gt;= 100 { break }</font></div><div><font face="Monaco" class="">}</font></div></blockquote><font face="Monaco" class="">}</font></blockquote><br class=""><div class="">With the ability to specify throwaway variables more easily, I'm sticking with my using syntax here:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Monaco" class="">var theNames:[String] = []</font></div><div class=""><font face="Monaco" class="">while let eachItem = theIterator.next() using (var theTotal = 0) where (theTotal &lt; 100) {</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>theNames.append(eachItem.name)</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>theTotal += eachItem.value</font></div><div class=""><font face="Monaco" class="">}</font></div></blockquote><br class=""><div class="">Depending upon your preference on how to structure the using and where parts this is shorter and easier.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">In terms of purely creating throwaway variables, it could be condensed a bit further if we stole anonymous variables from the closure syntax like so:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Monaco" class="">var theNames:[String] = []</font></div><div class=""><font face="Monaco" class="">while let eachItem = theIterator.next() using $0 = 0 where $0 &lt; 100 { // $0 is created for this block only</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>theNames.append(eachItem.name)</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>$0 += eachItem.value</font></div><div class=""><font face="Monaco" class="">}</font></div></blockquote><div class=""><br class=""></div><div class="">In other words, we'd treat $0 = 0 as a shorthand for var foo = 0 on the basis that it's being used for a limited scope (i.e- it's always an initialisation within the using clause, rather than an assignment). This should be consistent with closures on the basis that closures have implicitly created the variables for you.</div></body></html>