https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-04-08T09:16:59ZRuby Issue Tracking SystemRuby master - Feature #12262: Anti-loophttps://bugs.ruby-lang.org/issues/12262?journal_id=579792016-04-08T09:16:59Zjwille (Jens Wille)ww@blackwinter.de
<ul></ul><p>You can make your last example work with <code>loop</code> by just adding a <code>break</code> at the end of the loop body. I don't think that warrants a new method.</p> Ruby master - Feature #12262: Anti-loophttps://bugs.ruby-lang.org/issues/12262?journal_id=579862016-04-09T05:30:24Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I don't have any big pro or contra opinion, but there is one thing I am wondering:</p>
<p>Is this still called a loop in the second case? Because the default is to break<br>
after the first run. And a loop implies to continue, until one ends it or? :-)</p>
<p>However had, what I might find interesting, is to have other means to force the<br>
end of a loop. Like, "break" is used, but what if we could designate another<br>
way to end a loop? If we could do that, then perhaps your suggestion might be<br>
implied to work in the second case, because you could somehow specify that<br>
loop would en when a "return nil" would be implied.</p>
<p>E. g. something like (the syntax does not work, it just is an example):</p>
<pre><code>loop(break_on: nil) {
if ...
...
elsif ...
...
elsif ...
...
next # continues on exceptional cases
else
...
end
}
</code></pre>
<p>Where the default would be a loop like:</p>
<pre><code>loop(break_on: :break)
</code></pre>
<p>Which can be omitted. (The symbol :break would then default on the<br>
keyword break).</p>
<p>Please consider this just as food-for-thought, I actually do not<br>
really suggest it - I am just playing with the thought here. :)</p>
<p>(I myself probably would prefer "the simpler, the better" which<br>
is why I do not suggest a change, but as said, I am neutral on<br>
this suggestion.)</p>