220 3595 <85c0ae97-3440-4a81-96c2-1af7ebb892ba@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Andrew Sandoval <sandoval@netwaysglobal.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: "break break ;" etc. to break out of nested loops
Date: Fri, 5 Apr 2013 12:53:33 -0700 (PDT)
Lines: 114
Approved: news@gmane.org
Message-ID: <85c0ae97-3440-4a81-96c2-1af7ebb892ba@isocpp.org>
References: <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_526_31641456.1365191613317"
X-Trace: ger.gmane.org 1365273224 25858 80.91.229.3 (6 Apr 2013 18:33:44 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 6 Apr 2013 18:33:44 +0000 (UTC)
Cc: temptony@freemail.hu
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDIZ5RW5Y4IBBQGX7SFAKGQEKU3RE7A@isocpp.org Sat Apr 06 20:33:46 2013
Return-path: <std-proposals+bncBDIZ5RW5Y4IBBQGX7SFAKGQEKU3RE7A@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDIZ5RW5Y4IBBQGX7SFAKGQEKU3RE7A@isocpp.org>)
	id 1UOXKy-0004DB-F7
	for gclcip-std-proposals@m.gmane.org; Sat, 06 Apr 2013 19:55:36 +0200
Original-Received: by mail-ob0-f199.google.com with SMTP id va7sf308057obc.2
        for <gclcip-std-proposals@m.gmane.org>; Sat, 06 Apr 2013 10:55:35 -0700 (PDT)
X-Received: by 10.182.237.12 with SMTP id uy12mr3427769obc.20.1365191616304;
        Fri, 05 Apr 2013 12:53:36 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.132.110 with SMTP id ot14ls468082obb.18.gmail; Fri, 05 Apr
 2013 12:53:34 -0700 (PDT)
X-Received: by 10.182.16.35 with SMTP id c3mr283009obd.31.1365191614805;
        Fri, 05 Apr 2013 12:53:34 -0700 (PDT)
In-Reply-To: <1f964e4b-2762-43b8-85e5-41392926b07a@isocpp.org>
X-Original-Sender: sandoval@netwaysglobal.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:3595
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/3595>

------=_Part_526_31641456.1365191613317
Content-Type: text/plain; charset=ISO-8859-1

On Friday, April 5, 2013 2:23:33 PM UTC-5, temp...@freemail.hu wrote:
>
> 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?
>

How about *return*?  That way you are pushed towards keeping your functions 
simple.
Not trying to be negative, but that seems like something you wouldn't hit 
too often in C++ code -- C, yes, but hopefully not C++.

-Andrew Sandoval
 

-- 

--- 
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_526_31641456.1365191613317
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Friday, April 5, 2013 2:23:33 PM UTC-5, temp...@freemail.hu wrote:<block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;">I hesitate to suggest this simple en=
hancement to the language, because it's so obvious that <i>somebody</i> mus=
t have thought of it before. In which case there must have been a good reas=
on for rejecting it! But here goes:<div><div><br></div><div><i>Problem</i><=
/div><div>The <b>break</b>&nbsp;statement jumps out of the nearest enclosin=
g <b>do, for, switch, </b>or <b>while </b>statement. All programmers know t=
hat breaking out of a nested for-loop to the <i>second</i>-nearest enclosin=
g&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&nbsp;break</b> statement jumps out of=
 the second-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>&nb=
sp;<b>break&nbsp;</b>statemen<wbr>t jumps out of the third-nearest enclosin=
g&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>s=
tatement jumps out of the fourth-nearest enclosing&nbsp;<b>do, for, switch,=
&nbsp;</b>or&nbsp;<b>while&nbsp;</b>statement.<br></div><div><br></div><div=
>And so on. For instance:</div><div><br></div><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; &n=
bsp; &nbsp; // do stuff</div><div>&nbsp; &nbsp; &nbsp; if (a[i][j][k] =3D=
=3D 0) break break break ; // the same as "goto ContinueExecution ;"</div><=
div>&nbsp; &nbsp; }</div><div>ContinueExecution:<br></div><div><br></div><d=
iv>Easy to understand. Easy to implement. 100% backwards compatible. What's=
 not to like?</div></div></blockquote><div><br>How about <span style=3D"col=
or: rgb(0, 0, 255);"><b><span style=3D"font-family: courier new,monospace;"=
>return</span></b></span>?&nbsp; That way you are pushed towards keeping yo=
ur functions simple.<br>Not trying to be negative, but that seems like some=
thing you wouldn't hit too often in C++ code -- C, yes, but hopefully not C=
++.<br><br>-Andrew Sandoval<br>&nbsp;<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_526_31641456.1365191613317--

.
