<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I think that the C-style <i class="">for</i> loop should be removed from Swift. The scope rules for this <i class="">for</i> loop are wrong. Every loop sees the same scope. This is a source of bugs if you export the loop variable name outside the scope of the <i class="">for</i> statement, for example in a closure. The following code illustrates the problem:<div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> handlers: [() -> ()] = []</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> i <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>..<<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span> {</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">handlers</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">append</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span>(i) }</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> handler <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">handlers</span> {</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""> handler() <span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// "0 1 2 3 4"</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class="">handlers<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> = []</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> i = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>; i < <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span>; i += <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span> {</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">handlers</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">append</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span>(i) }</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">for</span> handler <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">handlers</span> {</div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""> handler() <span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// "5 5 5 5 5"</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">The Swift <i class="">for-in</i> loop does the right thing naturally. The C-style <i class="">for</i> loop does the wrong thing naturally. Removing the C-style <i class="">for</i> loop from Swift will eliminate one more class of possible errors from the language.</div></body></html>