220 27259 <c0a2a265-9128-490c-b80e-d9f7438df92a@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: gmisocpp@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: loop continuation code
Date: Mon, 25 Jul 2016 17:57:38 -0700 (PDT)
Lines: 231
Approved: news@gmane.org
Message-ID: <c0a2a265-9128-490c-b80e-d9f7438df92a@isocpp.org>
References: <2f575934-e078-411c-9c8a-c2996da7609d@isocpp.org>
 <28358863-5be0-401a-893a-0ae5385156c2@isocpp.org>
 <8ee79066-43c5-4624-8fb5-01172eb36d29@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1671_2115848116.1469494659019"
X-Trace: ger.gmane.org 1469494673 8856 80.91.229.3 (26 Jul 2016 00:57:53 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 26 Jul 2016 00:57:53 +0000 (UTC)
Cc: gmisocpp@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCM3TRNUXUDBBBHL3K6AKGQEUHDGO6Y@isocpp.org Tue Jul 26 02:57:44 2016
Return-path: <std-proposals+bncBCM3TRNUXUDBBBHL3K6AKGQEUHDGO6Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f200.google.com ([209.85.192.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCM3TRNUXUDBBBHL3K6AKGQEUHDGO6Y@isocpp.org>)
	id 1bRqgp-00058R-6b
	for gclcip-std-proposals@m.gmane.org; Tue, 26 Jul 2016 02:57:43 +0200
Original-Received: by mail-pf0-f200.google.com with SMTP id y134sf439541693pfg.1
        for <gclcip-std-proposals@m.gmane.org>; Mon, 25 Jul 2016 17:57:42 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=+DtTDjcY2Bl4FPP/+m02juQzJGWZwXQHEL/vz6J1mHU=;
        b=SjeO/SkmmWrrrAr0+AMRYYBbbC8HUxGWMat0vA52AB5hEPsiEUpDMilY4uOQaYFMQr
         0XsmWpUKXbMSU3/50hetDiyv4fIVWTRxxwGNt9ukfKAJn7SCGlr6Y1TbfGcNU4mZnPAz
         K6D7N8PUJBQ8zTsDyw4rJYeLwX/Rn8YpYDK/E2f8OCUvfvHIcgt15sangaqcn98DLJ5O
         20U8V5o+8QuOPqmerQZBd+w+RC8sNq3O9NBwt8ZCZDRKHv5pYQQ+h8wy6Usv9n3PXz/q
         5q2qZjceGwx0LOlHE7MwHqCcTNfWV/lls2Tkt3rNCVZzyzPNPFK09P7PtRal1SNT+GZR
         IujQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=+DtTDjcY2Bl4FPP/+m02juQzJGWZwXQHEL/vz6J1mHU=;
        b=MrGidyh6Jqz2Xe9SRye/BtW2s0DoG6Zd0UOiLl7yPrWF/riMSXPbBf1wFqiu6GTmWS
         vKsgS+TIzRsz7JsAx/wTgR7b9eNBvqCVKfY1iUMcZRqS4WFpRIaktcV/GfooDT5j720v
         XDIBrjGvi5JhnuJrU4gJ+5DMhjink5pRBacUcW4EHtFW32vR+386dYvqf6j69daTwLXW
         iGfDRaoP85IyzmMJNQr40kQb/L6kqEfIUWF/I0DeZi3pNbU8gxaj4Ev7foIzIy4bdDio
         9XFcISufeFEoyeXUNFOaJGAJT1tmtpbySZe4vSJgJlHK0zK0cmVGdMlZc53UUtqgCxMW
         LCSA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=+DtTDjcY2Bl4FPP/+m02juQzJGWZwXQHEL/vz6J1mHU=;
        b=acJB6tchJTPm+CK2NSV3W+ofvouk7gf18St6PO+pNKhd7GEGDLrEZYuhY8rfC9oWWR
         fkMop0XnJ1aWPW/tRTAdU0zHP3fS2UPGD6/odjPHC3ej5BJ0w4f+g/2nbULfJ05vSOEN
         3TG3CjHk1rY9ZIOIzUwhXhpFhH+TmzL4/oa4qY7YwPbKn2GfQwL4CFizRNMaGxzbAcjw
         txxADNG/D/Yw5FL0zv20PuBxD9dXovQIL+qIYqh/L2fuc1pGdAzc7M2jsqtZC7KyZ68h
         moUbCVwGQgHmoVRWBtVKjdTxQGbqh11kcUGVmjUvDXzOM/AzBPhxWjSo9CdP9bbUf2HH
         rEOw==
X-Gm-Message-State: AEkoouv2/9GQ/maXFICpqxdADtfxSjcVMPe6Bvoouwr3kUhmQPNfG1foWVXi4aAxsBxHlg==
X-Received: by 10.66.154.165 with SMTP id vp5mr18462507pab.44.1469494661978;
        Mon, 25 Jul 2016 17:57:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.75.133 with SMTP id q127ls3894367ita.14.gmail; Mon, 25 Jul
 2016 17:57:40 -0700 (PDT)
X-Received: by 10.36.50.145 with SMTP id j139mr595013ita.9.1469494660053;
        Mon, 25 Jul 2016 17:57:40 -0700 (PDT)
In-Reply-To: <8ee79066-43c5-4624-8fb5-01172eb36d29@isocpp.org>
X-Original-Sender: gmisocpp@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:27259
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/27259>

------=_Part_1671_2115848116.1469494659019
Content-Type: multipart/alternative; 
	boundary="----=_Part_1672_1187900692.1469494659019"

------=_Part_1672_1187900692.1469494659019
Content-Type: text/plain; charset=UTF-8



On Tuesday, July 26, 2016 at 12:01:38 PM UTC+12, Sean Middleditch wrote:
>
> Or just remove the variable i from the loop entirely because it's unused 
> in the loop body, thus reducing the for statement to:
>
>     for(; pUnicast != nullptr; pUnicat = pUnicast->Next)
>
> Not that a multi-statement increment wouldn't be useful, but this code 
> snippet is a pretty terrible motivating example. Sorry Glenn! :)
>

It's just some code I saw on reddit. But c'mon, you're being as 
unimaginative here as I've been lazy in crimping some random code to 
demonstrate the use case! lol
I'm not suggesting the need is desperate, but I have myself a few times in 
the past written loops where I've realised that I'd like to "continue 
early" a few times - much like returning early - to avoid complicating 
later code with logic just to avoid it being hit. But I'd still like to do 
something a bit more significant on each continue occasionally and not want 
to repeat that code or to have to try to shoe horn that logic into the 
increment statement of the loop or use a comma there where it just feels 
wrong and is too constrained.

I don't think you need to be that imaginative to see that ;) but hey I'm 
sure you won't be alone in your opinion if you still don't agree. I perhaps 
should contact the author of the original code and see if they agree if 
this facility would encourage them to use it over goto. That would a be a 
little interesting to me.

Thanks for your feedback.

 

>
> Anecdotally though (not that anyone cares, nor should you), I can't recall 
> a time I ever felt that I needed multiple loop incrementees without 
> eventually realizing that I was just writing my loop like an idiot. Or 
> missing an easily-written library facility to use with for-range iterator. 
> :)
>
> On Monday, July 25, 2016 at 8:08:23 AM UTC-7, Nicol Bolas wrote:
>>
>>
>> for ( int i = 0; pUnicast != NULL;
>>   pUnicast = pUnicast->Next; i++)
>> {
>>    Address address( (sockaddr_storage*) pUnicast->Address.lpSockaddr );
>>
>>    if ( !address.IsValid() )
>>       continue; // goto the continue block below
>>
>>    if ( address.IsLoopback() )
>>       continue;
>>
>>    if ( address.GetType() == ADDRESS_IPV6 && !address.IsGlobalUnicast() )
>>       continue;
>>
>>    addresses[numAddresses++] = address;
>>
>>    if ( numAddresses >= maxAddresses )
>>       break;
>> }
>>
>> This puts all of the iteration logic in the same place: the `for` 
>> statement itself. So if you want to see what happens on each loop, you 
>> don't have to look at both the top and the bottom of the `for` statement.
>>
>

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/c0a2a265-9128-490c-b80e-d9f7438df92a%40isocpp.org.

------=_Part_1672_1187900692.1469494659019
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, July 26, 2016 at 12:01:38 PM UTC+12, S=
ean Middleditch wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0p=
x 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); =
border-left-width: 1px; border-left-style: solid;"><div dir=3D"ltr">Or just=
 remove the variable i from the loop entirely because it&#39;s unused in th=
e loop body, thus reducing the for statement to:<div><br></div><div>=C2=A0 =
=C2=A0 for(; pUnicast !=3D nullptr; pUnicat =3D pUnicast-&gt;Next)<div><br>=
</div><div><div>Not that a multi-statement increment wouldn&#39;t be useful=
, but this code snippet is a pretty terrible motivating example. Sorry Glen=
n! :)</div></div></div></div></blockquote><div><br></div><div>It&#39;s just=
 some code I saw on reddit. But c&#39;mon, you&#39;re being as unimaginativ=
e here as I&#39;ve been lazy in crimping some random code to demonstrate=C2=
=A0the=C2=A0use case! lol</div><div>I&#39;m not suggesting the need=C2=A0is=
 desperate, but I have myself a few times in the past written loops where I=
&#39;ve realised that I&#39;d like to &quot;continue early&quot; a few time=
s - much like returning early - to avoid complicating later code=C2=A0with =
logic=C2=A0just to avoid it being hit. But I&#39;d still like to do somethi=
ng a bit more significant on each continue occasionally and not want to rep=
eat that code or=C2=A0to have to try to=C2=A0shoe horn that logic into the =
increment statement of the loop or use=C2=A0a comma there where it=C2=A0jus=
t feels wrong and is too constrained.</div><div><br></div><div>I don&#39;t =
think you need to be=C2=A0that imaginative to see that ;)=C2=A0but hey I&#3=
9;m sure you won&#39;t be alone in your opinion if you still don&#39;t agre=
e. I perhaps should contact the author of the original code and see if they=
 agree if this facility would encourage them to use it over goto. That woul=
d a be a little interesting to me.</div><div><br></div><div>Thanks for your=
 feedback.</div><div><br></div><div>=C2=A0</div><blockquote class=3D"gmail_=
quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-c=
olor: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;=
"><div dir=3D"ltr"><div><div><div><br></div><div>Anecdotally though (not th=
at anyone cares, nor should you), I can&#39;t recall a time I ever felt tha=
t I needed multiple loop incrementees without eventually realizing that I w=
as just writing my loop like an idiot. Or missing an easily-written library=
 facility to use with for-range iterator. :)</div><div><div><br>On Monday, =
July 25, 2016 at 8:08:23 AM UTC-7, Nicol Bolas wrote:<blockquote class=3D"g=
mail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-l=
eft-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: s=
olid;"><div dir=3D"ltr"><div><br><div style=3D"border: 1px solid rgb(187, 1=
87, 187); border-image: none; -ms-word-wrap: break-word; background-color: =
rgb(250, 250, 250);"><code><div><span style=3D"color: rgb(0, 0, 136);">for<=
/span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rg=
b(102, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 0);"> </span><span=
 style=3D"color: rgb(0, 0, 136);">int</span><span style=3D"color: rgb(0, 0,=
 0);"> i </span><span style=3D"color: rgb(102, 102, 0);">=3D</span><span st=
yle=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 102, 102)=
;">0</span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=3D"=
color: rgb(0, 0, 0);"> pUnicast </span><span style=3D"color: rgb(102, 102, =
0);">!=3D</span><span style=3D"color: rgb(0, 0, 0);"> NULL</span><span styl=
e=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"=
><br>=C2=A0 pUnicast </span><span style=3D"color: rgb(102, 102, 0);">=3D</s=
pan><span style=3D"color: rgb(0, 0, 0);"> pUnicast</span><span style=3D"col=
or: rgb(102, 102, 0);">-&gt;</span><span style=3D"color: rgb(102, 0, 102);"=
>Next</span><span style=3D"color: rgb(102, 102, 0);">;</span><span style=3D=
"color: rgb(0, 0, 0);"> i</span><span style=3D"color: rgb(102, 102, 0);">++=
)</span><span style=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"colo=
r: rgb(102, 102, 0);">{</span><span style=3D"color: rgb(0, 0, 0);"><br>=C2=
=A0 =C2=A0</span><span style=3D"color: rgb(102, 0, 102);">Address</span><sp=
an style=3D"color: rgb(0, 0, 0);"> address</span><span style=3D"color: rgb(=
102, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 0);"> </span><span s=
tyle=3D"color: rgb(102, 102, 0);">(</span><span style=3D"color: rgb(0, 0, 0=
);">sockaddr_storage</span><span style=3D"color: rgb(102, 102, 0);">*)</spa=
n><span style=3D"color: rgb(0, 0, 0);"> pUnicast</span><span style=3D"color=
: rgb(102, 102, 0);">-&gt;</span><span style=3D"color: rgb(102, 0, 102);">A=
ddress</span><span style=3D"color: rgb(102, 102, 0);">.</span><span style=
=3D"color: rgb(0, 0, 0);">lpSockaddr </span><span style=3D"color: rgb(102, =
102, 0);">);</span><span style=3D"color: rgb(0, 0, 0);"><br><br>=C2=A0 =C2=
=A0</span><span style=3D"color: rgb(0, 0, 136);">if</span><span style=3D"co=
lor: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">(</spa=
n><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(10=
2, 102, 0);">!</span><span style=3D"color: rgb(0, 0, 0);">address</span><sp=
an style=3D"color: rgb(102, 102, 0);">.</span><span style=3D"color: rgb(102=
, 0, 102);">IsValid</span><span style=3D"color: rgb(102, 102, 0);">()</span=
><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102=
, 102, 0);">)</span><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 =
=C2=A0 </span><span style=3D"color: rgb(0, 0, 136);">continue</span><span s=
tyle=3D"color: rgb(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0=
);"> </span><span style=3D"color: rgb(136, 0, 0);">// goto the continue blo=
ck below</span><span style=3D"color: rgb(0, 0, 0);"><br><br>=C2=A0 =C2=A0</=
span><span style=3D"color: rgb(0, 0, 136);">if</span><span style=3D"color: =
rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">(</span><sp=
an style=3D"color: rgb(0, 0, 0);"> address</span><span style=3D"color: rgb(=
102, 102, 0);">.</span><span style=3D"color: rgb(102, 0, 102);">IsLoopback<=
/span><span style=3D"color: rgb(102, 102, 0);">()</span><span style=3D"colo=
r: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">)</span>=
<span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 =C2=A0 </span><span =
style=3D"color: rgb(0, 0, 136);">continue</span><span style=3D"color: rgb(1=
02, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br><br>=C2=A0 =
=C2=A0</span><span style=3D"color: rgb(0, 0, 136);">if</span><span style=3D=
"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">(</=
span><span style=3D"color: rgb(0, 0, 0);"> address</span><span style=3D"col=
or: rgb(102, 102, 0);">.</span><span style=3D"color: rgb(102, 0, 102);">Get=
Type</span><span style=3D"color: rgb(102, 102, 0);">()</span><span style=3D=
"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">=3D=
=3D</span><span style=3D"color: rgb(0, 0, 0);"> ADDRESS_IPV6 </span><span s=
tyle=3D"color: rgb(102, 102, 0);">&amp;&amp;</span><span style=3D"color: rg=
b(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">!</span><span=
 style=3D"color: rgb(0, 0, 0);">address</span><span style=3D"color: rgb(102=
, 102, 0);">.</span><span style=3D"color: rgb(102, 0, 102);">IsGlobalUnicas=
t</span><span style=3D"color: rgb(102, 102, 0);">()</span><span style=3D"co=
lor: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">)</spa=
n><span style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 =C2=A0 </span><spa=
n style=3D"color: rgb(0, 0, 136);">continue</span><span style=3D"color: rgb=
(102, 102, 0);">;</span><span style=3D"color: rgb(0, 0, 0);"><br><br>=C2=A0=
 =C2=A0addresses</span><span style=3D"color: rgb(102, 102, 0);">[</span><sp=
an style=3D"color: rgb(0, 0, 0);">numAddresses</span><span style=3D"color: =
rgb(102, 102, 0);">++]</span><span style=3D"color: rgb(0, 0, 0);"> </span><=
span style=3D"color: rgb(102, 102, 0);">=3D</span><span style=3D"color: rgb=
(0, 0, 0);"> address</span><span style=3D"color: rgb(102, 102, 0);">;</span=
><span style=3D"color: rgb(0, 0, 0);"><br><br>=C2=A0 =C2=A0</span><span sty=
le=3D"color: rgb(0, 0, 136);">if</span><span style=3D"color: rgb(0, 0, 0);"=
> </span><span style=3D"color: rgb(102, 102, 0);">(</span><span style=3D"co=
lor: rgb(0, 0, 0);"> numAddresses </span><span style=3D"color: rgb(102, 102=
, 0);">&gt;=3D</span><span style=3D"color: rgb(0, 0, 0);"> maxAddresses </s=
pan><span style=3D"color: rgb(102, 102, 0);">)</span><span style=3D"color: =
rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: rgb(0,=
 0, 136);">break</span><span style=3D"color: rgb(102, 102, 0);">;</span><sp=
an style=3D"color: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(102,=
 102, 0);">}</span></div></code></div><br>This puts all of the iteration lo=
gic in the same place: the `for` statement itself. So if you want to see wh=
at happens on each loop, you don&#39;t have to look at both the top and the=
 bottom of the `for` statement.<br></div></div></blockquote></div></div></d=
iv></div></div></blockquote></div>

<p></p>

-- <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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/c0a2a265-9128-490c-b80e-d9f7438df92a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c0a2a265-9128-490c-b80e-d9f7438df92a=
%40isocpp.org</a>.<br />

------=_Part_1672_1187900692.1469494659019--

------=_Part_1671_2115848116.1469494659019--

.
