<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=""><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 = 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: “Use of unresolved identifier four.” 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="">{ </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 = 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></body></html>