<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=""><div class="">Strong +1 from me, I actually ran into a bunch of cases like this recently, having to put a tracking variable outside the loop feels weird; it makes sense for a regular while loop, but I see no reason that repeat/while couldn't have values from the loop be in scope for its condition.</div><div class=""><br class=""></div><div class="">There is a very slim chance of breakage if a variable is shadowed, can we use that as an excuse to get this done in Swift 3? =D</div><br class=""><div><blockquote type="cite" class=""><div class="">On 18 Jul 2016, at 18:52, Braeden Profile 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><font face="Monaco" class="">Good morning, Swift community!</font><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><font face="Monaco" class="">I’ve come across a situation a number of times where I write code that has to try something one or more times using a `repeat…while` loop and the condition relies upon variables that should be declared within the scope of the loop.</font></div><div class=""><br class=""></div><div class=""><font face="Monaco" class="">repeat</font></div><div class=""><font face="Monaco" class="">{</font></div><div class=""><span style="font-family: Monaco;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let success =&nbsp;doSomething()</span></div><div class=""><font face="Monaco" class="">}</font></div><div class=""><span style="font-family: Monaco;" class="">while !success</span></div><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><font face="Monaco" class="">The compiler unnecessarily prohibits this: &nbsp;“Use of unresolved identifier four.” &nbsp;In this simple case, we can write:</font></div><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><div class=""><font face="Monaco" class="">repeat</font></div><div class=""><font face="Monaco" class="">{&nbsp;</font><span style="font-family: Monaco;" class="">}</span></div><div class=""><span style="font-family: Monaco;" class="">while !</span><span style="font-family: Monaco;" class="">doSomething()</span></div></div><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><font face="Monaco" class="">But in a more complex situation, we are forced to write:</font></div><div class=""><font face="Monaco" class=""><br class=""></font></div><div class=""><font face="Monaco" class="">var success: Bool</font></div><div class=""><div class=""><font face="Monaco" class="">repeat</font></div><div class=""><font face="Monaco" class="">{</font></div><div class=""><span style="font-family: Monaco;" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>success =&nbsp;doSomething()</span></div><div class=""><font face="Monaco" class="">}</font></div><div class=""><span style="font-family: Monaco;" class="">while !success</span></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><span style="font-family: Monaco;" class="">We could change this so that the declarations within the top level scope of the loop are accessible from the condition.</span></div><div class=""><span style="font-family: Monaco;" class=""><br class=""></span></div><div class=""><span style="font-family: Monaco;" class="">Thanks for reading my first post to the Swift discussion board!</span></div><div class=""><span style="font-family: Monaco;" class="">—Braeden</span></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>