220 3619 <f29c2b6c-af86-44e0-a813-bd4b2efc01a7@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Benjamin Lindley <benjameslindley@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: "break break ;" etc. to break out of nested loops
Date: Sun, 7 Apr 2013 11:40:04 -0700 (PDT)
Lines: 172
Approved: news@gmane.org
Message-ID: <f29c2b6c-af86-44e0-a813-bd4b2efc01a7@isocpp.org>
References: <1f964e4b-2762-43b8-85e5-41392926b07a@isocpp.org>
 <51614514.2060103@bubblescope.net>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_2210_722238.1365360004986"
X-Trace: ger.gmane.org 1365360012 1097 80.91.229.3 (7 Apr 2013 18:40:12 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 7 Apr 2013 18:40:12 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDI7THWOWMDRBB73Q2FQKGQE5M3ICPI@isocpp.org Sun Apr 07 20:40:14 2013
Return-path: <std-proposals+bncBDI7THWOWMDRBB73Q2FQKGQE5M3ICPI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ve0-f199.google.com ([209.85.128.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDI7THWOWMDRBB73Q2FQKGQE5M3ICPI@isocpp.org>)
	id 1UOuVc-00081s-Ae
	for gclcip-std-proposals@m.gmane.org; Sun, 07 Apr 2013 20:40:08 +0200
Original-Received: by mail-ve0-f199.google.com with SMTP id jw11sf8628687veb.2
        for <gclcip-std-proposals@m.gmane.org>; Sun, 07 Apr 2013 11:40:07 -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: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=pgxEBkSyYjRkIqdbWdIc+BYQN+7G6tiXY6XHX0Q0/js=;
        b=Fnvj/8xB7IcBZftgVXAtTQ5E2GMt+tmoVadPsJm/eOPJD10ZeSW3GeONKlIHMD4BKg
         nbFl+YHR2dTkhwDlgHCqFfFr+4wx7J1lkug/neceLu5GPu1Kf30oXKLbondBIzqRfqwa
         T7o8JyG3qLg79A72l3ld9IrJxzgW4eaj2FXycJIHrrGyFpSo7eMvWVF/7BNzrhvNXYGc
         vjxPKPgzvcFufb3R6KbLq1pJ3qUcLaiswP0Wq4kXI+sajV3UkZuXXifU+SmkUmUG3Zp2
         GWab7r5QxnUOCXS0ahNCHNnCiHyoTohScrB6g3JTZO6/F9FUn4CcPETsKnFVHRtEgWYw
         5EXw==
X-Received: by 10.224.219.146 with SMTP id hu18mr4051814qab.3.1365360007426;
        Sun, 07 Apr 2013 11:40:07 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.3.99 with SMTP id b3ls2850676qeb.97.gmail; Sun, 07 Apr 2013
 11:40:05 -0700 (PDT)
X-Received: by 10.49.60.193 with SMTP id j1mr1240069qer.33.1365360005912;
        Sun, 07 Apr 2013 11:40:05 -0700 (PDT)
In-Reply-To: <51614514.2060103@bubblescope.net>
X-Original-Sender: benjameslindley@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:3619
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/3619>

------=_Part_2210_722238.1365360004986
Content-Type: text/plain; charset=ISO-8859-1

On Sunday, April 7, 2013 5:06:12 AM UTC-5, Chris Jefferson wrote:
>
>  On 05/04/13 20:23, temp...@freemail.hu <javascript:> 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?
>  
>
> Serious question: If this is equivalent to 'goto ContinueExecution', then 
> why not just teach people to use goto? That has the advantage that I don't 
> have to be careful to figure out where 'break break break;' will go, I can 
> see the label!
>
> Chris
>
 
It's only equivalent if the label ContinueExecution is actually there.  
With the goto, you can't be sure where it's actually going to until you 
actually find that label.  That could be up or down any distance within the 
function.  With "break break;", you know exactly where to look. Down to the 
end of the loop, and then down to the end of the next one.  Doesn't seem 
that hard to me.

-- 

--- 
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_2210_722238.1365360004986
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Sunday, April 7, 2013 5:06:12 AM UTC-5, Chris Jefferson wrote:<blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div>On 05/04/13 20:23, <a href=3D"javascript:" target=3D"_blank" gdf-o=
bfuscated-mailto=3D"mQMdeiDu2aEJ">temp...@freemail.hu</a>
      wrote:<br>
    </div>
    <blockquote type=3D"cite">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 case 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;statement 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 to
          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.</d=
iv>
        <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&nbs=
p;<b>while&nbsp;</b>statement.<br>
        </div>
        <div>The&nbsp;<b>break&nbsp;break</b>&nbsp;<b>break&nbsp;</b>statem=
en<wbr>t jumps out 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 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; &nbsp; &nbsp; // do stuff</div>
        <div>&nbsp; &nbsp; &nbsp; if (a[i][j][k] =3D=3D 0) break break brea=
k ; // the same
          as "goto ContinueExecution ;"</div>
        <div>&nbsp; &nbsp; }</div>
        <div>ContinueExecution:<br>
        </div>
        <div><br>
        </div>
        <div>Easy to understand. Easy to implement. 100% backwards
          compatible. What's not to like?</div>
      </div>
    </blockquote>
    <br>
    Serious question: If this is equivalent to 'goto ContinueExecution',
    then why not just teach people to use goto? That has the advantage
    that I don't have to be careful to figure out where 'break break
    break;' will go, I can see the label!<br>
    <br>
    Chris<br></div></blockquote><div>&nbsp;<br>It's only equivalent if the =
label ContinueExecution is actually there.&nbsp; With the goto, you can't b=
e sure where it's actually going to until you actually find that label.&nbs=
p; That could be up or down any distance within the function.&nbsp; With "b=
reak break;", you know exactly where to look. Down to the end of the loop, =
and then down to the end of the next one.&nbsp; Doesn't seem that hard to m=
e.<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_2210_722238.1365360004986--

.
