<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="">I don't think this use case warrants a syntax change since it can already be expressed quite elegantly with<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: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> test: [</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">]? = </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">nil</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">test</span><span style="font-variant-ligatures: no-common-ligatures" class="">?.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">forEach</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { i </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">in</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(i)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class=""><br class=""></div><div class="">Maybe "in?" could be used instead of&nbsp;</div><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: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> test: [</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">?] = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span><span style="font-variant-ligatures: no-common-ligatures" class="">]</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">for</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> i? </span><span style="font-variant-ligatures: no-common-ligatures" class="">in</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">test</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(i)</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div class="">?<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 11 Feb 2017, at 12:48, Tino Heth 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 style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This one started over at swift-users, with a question on how to deal with looping over containers that may be nil.<div class=""><br class=""></div><div class="">Imho the beauty of the feature is that it's simple enough to be explained in the subject line, but here is the "long" story:</div><div class=""><br class=""></div><div class=""><div class=""><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;test: [</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">]? =&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">nil</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div style="color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// this is possible now</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> test = test {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>for</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> i </span><span style="color: rgb(186, 45, 162); font-variant-ligatures: no-common-ligatures;" class="">in</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> test {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="Apple-tab-span" style="white-space:pre">                </span></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(62, 30, 129);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(i)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="color: rgb(186, 45, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);"><div style="color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">// how it could be written with a modified keyword</span></div></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">for</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;i&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">in?</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;test</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;{</span></div></span></div></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-tab-span" style="white-space: pre;">        </span>print</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(i)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures;">}</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="">I've been thinking "in?" had been brought up long ago, but as I haven't found such a proposal, I probably confused it with the cancelled plan to write one on my own (or I just was to stupid to search ;-).</div><div class=""><br class=""></div><div class="">Syntactic sugar like this is definitely nothing that has priority now, but discussing it shouldn't be a big distraction — and if it turns into a proposal that as well survives review, it might be even simple enough to act as a trigger for me to finally get my hands on some real work for Swift ;-)</div><div class=""><br class=""></div><div class="">- Tino</div></span></div></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=""></div></div></body></html>