<div dir="ltr">If I might be so bold, perhaps we should consider the opposite. Suppose you have a conditional statement inside a loop. It would be easier for the reader to understand what it does if “break” meant the same thing regardless of whether you used “if” or “switch” for the condition.<div><br></div><div>Right now, these two loops behave differently:</div><div><div><br></div><div><div>let seq = [1, 2, 3]</div><div><br></div><div>for x in seq { // prints ! 2 ! 3 !</div><div> switch x {</div><div> case 1: break</div><div> case _: print(x)</div><div> }</div><div> print("!")</div><div>}</div><div><br></div><div>for x in seq { // prints nothing</div><div> if x == 1 {</div><div> break</div><div> } else {</div><div> print(x)</div><div> }</div><div> print("!")</div><div>}</div></div><div><br></div><div>In particular, the current behavior of “break” means you need to label the loop if you want to break out of it from a “switch”, but not from an “if”. This is at least inconsistent.</div><div><br></div><div>Nevin</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 13, 2016 at 7:59 AM, Haravikk via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class=""><br><div><blockquote type="cite"><div>On 13 Oct 2016, at 12:26, Alex Blewitt <<a href="mailto:alblue@apple.com" target="_blank">alblue@apple.com</a>> wrote:</div><br class="m_-7565894703317434221Apple-interchange-newline"><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">On 13 Oct 2016, at 11:06, Haravikk via swift-evolution <</span><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">> wrote:</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><br class="m_-7565894703317434221Apple-interchange-newline"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div><br class="m_-7565894703317434221Apple-interchange-newline">On 11 Oct 2016, at 19:43, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-7565894703317434221Apple-interchange-newline"><div><div style="word-wrap:break-word">I thought this was long gone but today I found out it is still legal:<div><br></div><div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures">switch</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-7565894703317434221Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">i</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-7565894703317434221Apple-converted-space"> </span>{</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">case</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-7565894703317434221Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">4</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-7565894703317434221Apple-converted-space"> </span>...<span class="m_-7565894703317434221Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">6</span><span style="font-variant-ligatures:no-common-ligatures">: ()</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">case</span><span style="font-variant-ligatures:no-common-ligatures"><span class="m_-7565894703317434221Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)">3</span><span style="font-variant-ligatures:no-common-ligatures">:<span class="m_-7565894703317434221Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">print</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures">"Here"</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)"><span style="font-variant-ligatures:no-common-ligatures">default</span><span style="font-variant-ligatures:no-common-ligatures">:<span class="m_-7565894703317434221Apple-converted-space"> </span></span><span style="font-variant-ligatures:no-common-ligatures">break</span></div><div style="margin:0px;font-size:16px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div><br></div><div>Is there a motivating factor for keeping this in the language? The compiler picks up on Void and emits an error. You'd think () would produce the same results but it doesn't.</div></div><div><br></div><div>— Erica</div></div></div></blockquote><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Hopefully I'm not the only one but… how are we<span class="m_-7565894703317434221Apple-converted-space"> </span><b>supposed</b><span class="m_-7565894703317434221Apple-converted-space"> </span>to be doing this? Because () is exactly what I've been using the entire time for cases that I want to ignore (or are handled in code outside the switch). I'm going to have a few dozen files to edit if there's something else I'm supposed to be using… </div></div></blockquote><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">You can have a 'break' there, which is equivalent to a nop but without a return value. Whether that's what you're supposed to do or not is a different issue :)</div></div></blockquote><br></div></span><div>Perhaps too philosophical a question? ^^</div><div><br></div><div>You're right though, I probably should be using breaks as they're more explicit, and I suppose fallthrough should work too so all cases should be covered without having to use (), in that case it maybe is something worth getting rid of?</div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>