From: Brandon Weaver Date: 2016-04-08T00:26:07-07:00 Subject: [ruby-core:74850] Re: [Ruby trunk Feature#12262] Anti-loop --===============0965575517== Content-Type: multipart/alternative; boundary=001a113ed12ec456df052ff41b7f --001a113ed12ec456df052ff41b7f Content-Type: text/plain; charset=UTF-8 [1].each { puts 'looping'; sleep 1; redo } On Fri, Apr 8, 2016 at 12:21 AM, wrote: > Issue #12262 has been reported by Tsuyoshi Sawada. > > ---------------------------------------- > Feature #12262: Anti-loop > https://bugs.ruby-lang.org/issues/12262 > > * Author: Tsuyoshi Sawada > * Status: Open > * Priority: Normal > * Assignee: > ---------------------------------------- > The `loop` method continues by default, and requires the keyword `break` > to escape. This is good when the continuing cases are the norm and the > escaping cases are exceptional: > > ~~~RUBY > loop do > ... > if ... > ... > elsif ... > ... > elsif ... > ... > break # breaks on exceptional cases > elsif ... > ... > else > ... > end > end > ~~~ > > But when the continuing cases are exceptional and the escaping cases are > the norm, the construction requires a lot of `break`, and it becomes > cumbersome: > > ~~~RUBY > loop do > ... > if ... > ... > break # lot of breaks > elsif ... > ... > break # lot of breaks > elsif ... > ... > break # lot of breaks > elsif ... > ... > else > ... > break # lot of breaks > end > end > ~~~ > > I actually see this use case a lot when user input is asked with > validation on a command line script. > > I request a `loop`-like method that works in the opposite way to `loop`, > that is, it escapes (i.e., runs only once) by default, and requires a > keyword to continue (perhaps `next`). The second code above would then be > written like: > > ~~~RUBY > some_loop_like_method do > ... > if ... > ... > elsif ... > ... > elsif ... > ... > elsif ... > ... > next # continues on exceptional cases > else > ... > end > end > ~~~ > > > > > -- > https://bugs.ruby-lang.org/ > > Unsubscribe: > > --001a113ed12ec456df052ff41b7f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

[1].each { puts 'lo= oping'; sleep 1; redo }


On Fri, Apr 8, 2016 at 12:21 AM, &l= t;sawadatsuyo= shi@gmail.com> wrote:
Issue= #12262 has been reported by Tsuyoshi Sawada.

----------------------------------------
Feature #12262: Anti-loop
https://bugs.ruby-lang.org/issues/12262

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
The `loop` method continues by default, and requires the keyword `break` to= escape. This is good when the continuing cases are the norm and the escapi= ng cases are exceptional:

~~~RUBY
loop do
=C2=A0 ...
=C2=A0 if ...
=C2=A0 =C2=A0 ...
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 break # breaks on exceptional cases
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 else
=C2=A0 =C2=A0 ...
=C2=A0 end
end
~~~

But when the continuing cases are exceptional and the escaping cases are th= e norm, the construction requires a lot of `break`, and it becomes cumberso= me:

~~~RUBY
loop do
=C2=A0 ...
=C2=A0 if ...
=C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 break # lot of breaks
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 break # lot of breaks
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 break # lot of breaks
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 else
=C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 break # lot of breaks
=C2=A0 end
end
~~~

I actually see this use case a lot when user input is asked with validation= on a command line script.

I request a `loop`-like method that works in the opposite way to `loop`, th= at is, it escapes (i.e., runs only once) by default, and requires a keyword= to continue (perhaps `next`). The second code above would then be written = like:

~~~RUBY
some_loop_like_method do
=C2=A0 ...
=C2=A0 if ...
=C2=A0 =C2=A0 ...
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 elsif ...
=C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 next # continues on exceptional cases
=C2=A0 else
=C2=A0 =C2=A0 ...
=C2=A0 end
end
~~~




--
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:= ruby-core-request@ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-core>

--001a113ed12ec456df052ff41b7f-- --===============0965575517== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============0965575517==--