220 3584 <1f964e4b-2762-43b8-85e5-41392926b07a@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: temptony@freemail.hu
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: "break break ;" etc. to break out of nested loops
Date: Fri, 5 Apr 2013 12:23:33 -0700 (PDT)
Lines: 95
Approved: news@gmane.org
Message-ID: <1f964e4b-2762-43b8-85e5-41392926b07a@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_388_11946196.1365189813293"
X-Trace: ger.gmane.org 1365268599 14867 80.91.229.3 (6 Apr 2013 17:16:39 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 6 Apr 2013 17:16:39 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCF55ZN354IBBPWJ7SFAKGQES6YKS7Q@isocpp.org Sat Apr 06 19:16:41 2013
Return-path: <std-proposals+bncBCF55ZN354IBBPWJ7SFAKGQES6YKS7Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qe0-f71.google.com ([209.85.128.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCF55ZN354IBBPWJ7SFAKGQES6YKS7Q@isocpp.org>)
	id 1UOWIV-0006hM-2l
	for gclcip-std-proposals@m.gmane.org; Sat, 06 Apr 2013 18:48:59 +0200
Original-Received: by mail-qe0-f71.google.com with SMTP id b10sf3873538qen.10
        for <gclcip-std-proposals@m.gmane.org>; Sat, 06 Apr 2013 09:48:58 -0700 (PDT)
X-Received: by 10.236.139.230 with SMTP id c66mr5377054yhj.55.1365189823258;
        Fri, 05 Apr 2013 12:23:43 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.87.196 with SMTP id ba4ls392322qeb.3.gmail; Fri, 05 Apr
 2013 12:23:33 -0700 (PDT)
X-Received: by 10.49.27.102 with SMTP id s6mr1121494qeg.1.1365189813845;
        Fri, 05 Apr 2013 12:23:33 -0700 (PDT)
X-Original-Sender: temptony@freemail.hu
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:3584
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/3584>

------=_Part_388_11946196.1365189813293
Content-Type: text/plain; charset=ISO-8859-1

I hesitate to suggest this simple enhancement to the language, because it's 
so obvious that *somebody* must have thought of it before. In which case 
there must have been a good reason for rejecting it! But here goes:

*Problem*
The *break* statement jumps out of the nearest enclosing *do, for, switch, *or 
*while *statement. All programmers know that breaking out of a nested 
for-loop to the *second*-nearest enclosing *do, for, switch, *or *while *statement 
is a pain, and requires a *goto* statement or worse.

*Suggestion*
I suggest the following syntax:

The *break break* statement jumps out of the second-nearest enclosing *do, 
for, switch, *or *while *statement.
The *break break* *break *statement jumps out of the third-nearest 
enclosing *do, for, switch, *or *while *statement.
The *break break* *break break *statement jumps out of the fourth-nearest 
enclosing *do, for, switch, *or *while *statement.

And so on. For instance:

for (int i = 0 ; i < 10 ; i++)
  for (int j = 0 ; j < 10 ; j++)
    for (int k = 0 ; k < 10 ; k++) {
      // do stuff
      if (a[i][j][k] == 0) break break break ; // the same as "goto 
ContinueExecution ;"
    }
ContinueExecution:

Easy to understand. Easy to implement. 100% backwards compatible. What's 
not to like?

-- 

--- 
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 email 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-proposals/?hl=en.



------=_Part_388_11946196.1365189813293
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

I hesitate to suggest this simple enhancement to the language, because it's=
 so obvious that <i>somebody</i> must have thought of it before. In which c=
ase there must have been a good reason for rejecting it! But here goes:<div=
><div><br></div><div><i>Problem</i></div><div>The <b>break</b>&nbsp;stateme=
nt jumps out of the nearest enclosing <b>do, for, switch, </b>or <b>while <=
/b>statement. All programmers know that breaking out of a nested for-loop t=
o the <i>second</i>-nearest enclosing&nbsp;<b>do, for, switch,&nbsp;</b>or&=
nbsp;<b>while&nbsp;</b>statement is a pain, and requires a <b>goto</b>&nbsp=
;statement or worse.</div><div><br></div><div><i>Suggestion</i></div><div>I=
 suggest the following syntax:</div><div><br></div><div>The&nbsp;<b>break&n=
bsp;break</b> statement jumps out of the second-nearest enclosing&nbsp;<b>d=
o, for, switch,&nbsp;</b>or&nbsp;<b>while&nbsp;</b>statement.<br></div><div=
>The&nbsp;<b>break&nbsp;break</b>&nbsp;<b>break&nbsp;</b>statement jumps ou=
t of the third-nearest enclosing&nbsp;<b>do, for, switch,&nbsp;</b>or&nbsp;=
<b>while&nbsp;</b>statement.<br></div><div>The&nbsp;<b>break&nbsp;break</b>=
&nbsp;<b>break break&nbsp;</b>statement jumps out of the fourth-nearest enc=
losing&nbsp;<b>do, for, switch,&nbsp;</b>or&nbsp;<b>while&nbsp;</b>statemen=
t.<br></div><div><br></div><div>And so on. For instance:</div><div><br></di=
v><div>for (int i =3D 0 ; i &lt; 10 ; i++)</div><div>&nbsp; for (int j =3D =
0 ; j &lt; 10 ; j++)</div><div>&nbsp; &nbsp; for (int k =3D 0 ; k &lt; 10 ;=
 k++) {<br></div><div>&nbsp; &nbsp; &nbsp; // do stuff</div><div>&nbsp; &nb=
sp; &nbsp; if (a[i][j][k] =3D=3D 0) break break break ; // the same as "got=
o ContinueExecution ;"</div><div>&nbsp; &nbsp; }</div><div>ContinueExecutio=
n:<br></div><div><br></div><div>Easy to understand. Easy to implement. 100%=
 backwards compatible. What's not to like?</div></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_388_11946196.1365189813293--

.
