220 3598 <b1210fad-f90d-4964-aec2-102fb814c44c@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: morwenn29@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: "break break ;" etc. to break out of nested loops
Date: Sat, 6 Apr 2013 02:23:01 -0700 (PDT)
Lines: 137
Approved: news@gmane.org
Message-ID: <b1210fad-f90d-4964-aec2-102fb814c44c@isocpp.org>
References: <1f964e4b-2762-43b8-85e5-41392926b07a@isocpp.org> <CAOHCbiuv0zLyEu-7RJR9rLzs-zwQRrxbkYjfO3jHTJj2GrGgYQ@mail.gmail.com>
 <515FC3B0.2090803@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_2600_9437091.1365240181315"
X-Trace: ger.gmane.org 1365274122 8506 80.91.229.3 (6 Apr 2013 18:48:42 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 6 Apr 2013 18:48:42 +0000 (UTC)
Cc: Tony V E <tvaneerd@gmail.com>
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC2ZP4V74IFBB56S76FAKGQEYNHR6HQ@isocpp.org Sat Apr 06 20:48:43 2013
Return-path: <std-proposals+bncBC2ZP4V74IFBB56S76FAKGQEYNHR6HQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f198.google.com ([209.85.216.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC2ZP4V74IFBB56S76FAKGQEYNHR6HQ@isocpp.org>)
	id 1UOXf6-0001Bx-Hw
	for gclcip-std-proposals@m.gmane.org; Sat, 06 Apr 2013 20:16:24 +0200
Original-Received: by mail-qc0-f198.google.com with SMTP id v20sf6159646qcm.1
        for <gclcip-std-proposals@m.gmane.org>; Sat, 06 Apr 2013 11:16:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-received:x-beenthere:x-received:date:from:to:cc:message-id
         :in-reply-to:references:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-google-group-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=ghAMZfWeicb4ftYckpCAOpwlFvNAnDTN5MRKjvH31yI=;
        b=LBgAmrGp/NsTRv7j6eOXxGu/uM4OHe3NYqrAdNFEcMgiwkfIoXqHQcp8uNbUpeG2rQ
         UFTPkbt1EDVE1oIeaUVeZZgt6nsjcspgkG22zXzEzFAqjG54zy9/UYKVqdOZvg6tp21F
         63ivuaHt7AE+neuowFojcPz8xz8S6h3LJXWvRYZkuSmFRH3uhjn2HpECjMNP+eMWSvkA
         0wFxhz4sF43Nocq8DaItY1EyDaV1zgkJeryTpVveSzUja1kQxB18WJ5pA4eAVtGc9s64
         A2vR7Df8KTQ+W8xEL2ZFekuMWRRtGCY8LPa/aQadGEpkwFl5eCyn8uSrfsU51YywvsLB
         jBvw==
X-Received: by 10.224.172.200 with SMTP id m8mr924214qaz.0.1365240183807;
        Sat, 06 Apr 2013 02:23:03 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.98.101 with SMTP id eh5ls2264132qeb.95.gmail; Sat, 06 Apr
 2013 02:23:02 -0700 (PDT)
X-Received: by 10.49.85.106 with SMTP id g10mr1240255qez.13.1365240182095;
        Sat, 06 Apr 2013 02:23:02 -0700 (PDT)
In-Reply-To: <515FC3B0.2090803@gmail.com>
X-Original-Sender: morwenn29@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:3598
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/3598>

------=_Part_2600_9437091.1365240181315
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Le samedi 6 avril 2013 08:41:52 UTC+2, Chip Salzenberg a =E9crit :
>
> On 4/5/2013 3:23 PM, Tony V E wrote:=20
> > label: for (;;)=20
> > {=20
> >    break label;=20
> > }=20
>
> Yes, please; if this must be done, this is the way.  It's one of the=20
> things that's actually worth borrowing from Perl.  The label is=20
> semantically useful, and not brittle if another level is added.  Thus:=20
>
>     line:=20
>       while (cin >> s) {=20
>           ...=20
>           if (COND) continue line;=20
>           ...=20
>       }
>
=20
 That seems to be the only viable way to go for this kind of problem. The=
=20
break 1, break 2, break 3, etc... is easy to understand but, even as a=20
compile-time constant, I dont want to imagine what could be done with such=
=20
a construct (well, I don't want to know, but never see it in real code):

    template<unsigned N>
    void foobar()
    {
        for (...;...;...) {
            for (...;...;...) {
                for (...;...;...) {
                    break N; // sit down and enjoy the complexity as if=20
there was no tomorrow
                }
            }
        }
    }

Well, this kind of problems will never be encountered with a labeled break.=
=20
But the label break is more verbose is the sense we need to label name.
In most of the cases, putting the nested loops in a function and using=20
return is enough.

If you want to read some more things about those breaks, there has been a=
=20
proposal for Python:
http://www.python.org/dev/peps/pep-3136/
It has been rejected, the reasons are included. That could be a good thing=
=20
to read.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.



------=_Part_2600_9437091.1365240181315
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Le samedi 6 avril 2013 08:41:52 UTC+2, Chip Salzenberg a =E9crit&nbsp;:<blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;">On 4/5/2013 3:23 PM, Tony V E wrot=
e:
<br>&gt; label: for (;;)
<br>&gt; {
<br>&gt; &nbsp; &nbsp;break label;
<br>&gt; }
<br>
<br>Yes, please; if this must be done, this is the way. &nbsp;It's one of t=
he
<br>things that's actually worth borrowing from Perl. &nbsp;The label is
<br>semantically useful, and not brittle if another level is added. &nbsp;T=
hus:
<br>
<br>&nbsp; &nbsp; line:
<br>&nbsp; &nbsp; &nbsp; while (cin &gt;&gt; s) {
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (COND) continue line;
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...
<br>&nbsp; &nbsp; &nbsp; }<br></blockquote><div>&nbsp;</div><div>&nbsp;That=
 seems to be the only viable way to go for this kind of problem. The break =
1, break 2, break 3, etc... is easy to understand but, even as a compile-ti=
me constant, I dont want to imagine what could be done with such a construc=
t (well, I don't want to know, but never see it in real code):<br><br>&nbsp=
;&nbsp;&nbsp; template&lt;unsigned N&gt;<br>&nbsp;&nbsp;&nbsp; void foobar(=
)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for=
 (...;...;...) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; for (...;...;...) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (...;...;...) {<br>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break N; // sit down and enjoy the c=
omplexity as if there was no tomorrow<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>Well, this kind=
 of problems will never be encountered with a labeled break. But the label =
break is more verbose is the sense we need to label name.<br>In most of the=
 cases, putting the nested loops in a function and using return is enough.<=
br><br>If you want to read some more things about those breaks, there has b=
een a proposal for Python:<br>http://www.python.org/dev/peps/pep-3136/<br>I=
t has been rejected, the reasons are included. That could be a good thing t=
o read.<br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_2600_9437091.1365240181315--

.
