220 27258 <8ee79066-43c5-4624-8fb5-01172eb36d29@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Sean Middleditch <sean.middleditch@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: loop continuation code
Date: Mon, 25 Jul 2016 17:01:37 -0700 (PDT)
Lines: 159
Approved: news@gmane.org
Message-ID: <8ee79066-43c5-4624-8fb5-01172eb36d29@isocpp.org>
References: <2f575934-e078-411c-9c8a-c2996da7609d@isocpp.org>
 <28358863-5be0-401a-893a-0ae5385156c2@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1277_712424841.1469491298070"
X-Trace: ger.gmane.org 1469491304 24681 80.91.229.3 (26 Jul 2016 00:01:44 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 26 Jul 2016 00:01:44 +0000 (UTC)
Cc: gmisocpp@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCDODCNR2QPRBY6Q3K6AKGQE56SDVKI@isocpp.org Tue Jul 26 02:01:44 2016
Return-path: <std-proposals+bncBCDODCNR2QPRBY6Q3K6AKGQE56SDVKI@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+bncBCDODCNR2QPRBY6Q3K6AKGQE56SDVKI@isocpp.org>)
	id 1bRpoc-0006ok-MP
	for gclcip-std-proposals@m.gmane.org; Tue, 26 Jul 2016 02:01:42 +0200
Original-Received: by mail-pf0-f200.google.com with SMTP id h186sf432859925pfg.3
        for <gclcip-std-proposals@m.gmane.org>; Mon, 25 Jul 2016 17:01: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=Y6OTYc9CCS445r1beWWmoX8BR8p8+3s9soIFYebHzBA=;
        b=FiUkvo/HY1gci1tvNPMeIcPn5TEnaLmj/bNHFKe4MoGuubpSz0XI7+R1EZAxld8Bns
         +zaAZ6+bG0VyG680dEGkxwNXCgEnkB9mabGkvVMSadVSmdxuU4Z9PCunCqWvwYxpdB4B
         8oNTbX3bZey7TdoaEkCueuy67MwJb8y/IfCrYfRr8v2BbasUs+o1g/UQLcCDbFZI8++Y
         guhKdQqLpjQsn71ZQJ3+fv/KLwIQhq5bStARWTwoi7vMDyZez3o2T00mLxmFqchBF9Aa
         kBLNGIns0N+F1q/UCZXoGXuHmZy1SAC+W3cd2v090exu1SC4WLXW+TGZ7szKUOEP99sE
         fjTA==
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=Y6OTYc9CCS445r1beWWmoX8BR8p8+3s9soIFYebHzBA=;
        b=XFdAmvxLqo6SkpBkbA+cRTk4OmI9thwJJsWnhEm5Oii9d+Wu2LyxjWJXaDjbtOuj9b
         BLPPCfauVd6KRiCaapK9BKQe0NJoUkW5N5FTBQ32bZ6sKkWNCjIcefks0oS9C9vnxLmw
         MBaAz2YYMjCveBTEnggLdvNUgMH2eleKJeUA5xC781oT47RIx1MdHVqsHQWmOl9QhDQn
         wSWpewiQaY+nxG+XffE0UOmVB21eFtqROt2oIFgdATemle89XfmHRV2mrc6iqQ6IwXbh
         HPq0RAOk9EZZESOSNhSG8YVkvnHCrZ7eNRtX3F1TXqt2jxKS1e4MeE9Tj2cnvC5VL02R
         uczQ==
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=Y6OTYc9CCS445r1beWWmoX8BR8p8+3s9soIFYebHzBA=;
        b=T84IaVhdRzlbYavRzovFpQ86G9oIn/kE7YUauU1+mkg7nOv2TBPM4pHdAZxMxT9TsP
         AAJ/QGEUidKUKhdY2fPJUeRW5k9EPtiIaEBx4RDglj3ZAPc32gjDMbfu0IStKFNNoykS
         63s/z/KuLmDkPwjmSe/0Mg+0n6gf3JLy5EBBCJnSoFStFDriesRt6j6V53NlaMtfKcjy
         GwJOio99JQAROxPXVZHUKlX13cI9GcpMEGy/I+nf2mUNI455cwFFycDFw8giHU9VAkv7
         qrOQTW1XeOrlvKMrUwnnE7tN2eoiFmdvphoHLZUuKgy/ee0Gfv3dEQuR8ZYntwcGz0Bq
         iKwA==
X-Gm-Message-State: AEkoousJcG50MZ0Rvh0o0xShTwGhRmpvaUciMZPEHNkyQlwMIicsUOqeMBHzylEwDnN4vA==
X-Received: by 10.98.20.196 with SMTP id 187mr17902681pfu.0.1469491301186;
        Mon, 25 Jul 2016 17:01:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.25.212 with SMTP id 203ls3688466ioz.40.gmail; Mon, 25 Jul
 2016 17:01:39 -0700 (PDT)
X-Received: by 10.36.227.67 with SMTP id d64mr3354798ith.3.1469491298984;
        Mon, 25 Jul 2016 17:01:38 -0700 (PDT)
In-Reply-To: <28358863-5be0-401a-893a-0ae5385156c2@isocpp.org>
X-Original-Sender: Sean.Middleditch@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:27258
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/27258>

------=_Part_1277_712424841.1469491298070
Content-Type: multipart/alternative; 
	boundary="----=_Part_1278_2027970891.1469491298078"

------=_Part_1278_2027970891.1469491298078
Content-Type: text/plain; charset=UTF-8

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! :)

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/8ee79066-43c5-4624-8fb5-01172eb36d29%40isocpp.org.

------=_Part_1278_2027970891.1469491298078
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Or just remove the variable i from the loop entirely becau=
se it&#39;s unused in the loop body, thus reducing the for statement to:<di=
v><br></div><div>=C2=A0 =C2=A0 for(; pUnicast !=3D nullptr; pUnicat =3D pUn=
icast-&gt;Next)<div><br></div><div><div>Not that a multi-statement incremen=
t wouldn&#39;t be useful, but this code snippet is a pretty terrible motiva=
ting example. Sorry Glenn! :)</div><div><br></div><div>Anecdotally though (=
not that anyone cares, nor should you), I can&#39;t recall a time I ever fe=
lt that I needed multiple loop incrementees without eventually realizing th=
at I was just writing my loop like an idiot. Or missing an easily-written l=
ibrary facility to use with for-range iterator. :)</div><div><div><br>On Mo=
nday, July 25, 2016 at 8:08:23 AM UTC-7, Nicol Bolas wrote:<blockquote clas=
s=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #c=
cc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><br><div style=3D"backgr=
ound-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:soli=
d;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#0=
08">for</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>(</span><span style=3D"color:#000"> </span><span style=3D"color:#008">int<=
/span><span style=3D"color:#000"> i </span><span style=3D"color:#660">=3D</=
span><span style=3D"color:#000"> </span><span style=3D"color:#066">0</span>=
<span style=3D"color:#660">;</span><span style=3D"color:#000"> pUnicast </s=
pan><span style=3D"color:#660">!=3D</span><span style=3D"color:#000"> NULL<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=
=A0 pUnicast </span><span style=3D"color:#660">=3D</span><span style=3D"col=
or:#000"> pUnicast</span><span style=3D"color:#660">-&gt;</span><span style=
=3D"color:#606">Next</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"> i</span><span style=3D"color:#660">++)</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0</span><span style=3D"color:#606">Address<=
/span><span style=3D"color:#000"> address</span><span style=3D"color:#660">=
(</span><span style=3D"color:#000"> </span><span style=3D"color:#660">(</sp=
an><span style=3D"color:#000">sockaddr_storage</span><span style=3D"color:#=
660">*)</span><span style=3D"color:#000"> pUnicast</span><span style=3D"col=
or:#660">-&gt;</span><span style=3D"color:#606">Address</span><span style=
=3D"color:#660">.</span><span style=3D"color:#000">lpSockaddr </span><span =
style=3D"color:#660">);</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=
=A0</span><span style=3D"color:#008">if</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">(</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">!</span><span style=3D"color:#000">address</spa=
n><span style=3D"color:#660">.</span><span style=3D"color:#606">IsValid</sp=
an><span style=3D"color:#660">()</span><span style=3D"color:#000"> </span><=
span style=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 =C2=A0 </span><span style=3D"color:#008">continue</span><span style=3D"=
color:#660">;</span><span style=3D"color:#000"> </span><span style=3D"color=
:#800">// goto the continue block below</span><span style=3D"color:#000"><b=
r><br>=C2=A0 =C2=A0</span><span style=3D"color:#008">if</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000"> address</span><span style=3D"color:#660">.</span><span style=3D=
"color:#606">IsLoopback</span><span style=3D"color:#660">()</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">)</span><span style=3D=
"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">con=
tinue</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br><br>=C2=A0 =C2=A0</span><span style=3D"color:#008">if</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000"> address</span><span style=3D"color:#660">.</span><span style=3D=
"color:#606">GetType</span><span style=3D"color:#660">()</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">=3D=3D</span><span style=
=3D"color:#000"> ADDRESS_IPV6 </span><span style=3D"color:#660">&amp;&amp;<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#660">!</span=
><span style=3D"color:#000">address</span><span style=3D"color:#660">.</spa=
n><span style=3D"color:#606">IsGlobalUnicast</span><span style=3D"color:#66=
0">()</span><span style=3D"color:#000"> </span><span style=3D"color:#660">)=
</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 </span><span sty=
le=3D"color:#008">continue</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br><br>=C2=A0 =C2=A0addresses</span><span style=3D"col=
or:#660">[</span><span style=3D"color:#000">numAddresses</span><span style=
=3D"color:#660">++]</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#000"> address</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br><br>=C2=A0 =C2=A0</=
span><span style=3D"color:#008">if</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">(</span><span style=3D"color:#000"> numAddresse=
s </span><span style=3D"color:#660">&gt;=3D</span><span style=3D"color:#000=
"> maxAddresses </span><span style=3D"color:#660">)</span><span style=3D"co=
lor:#000"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">break<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br></s=
pan><span style=3D"color:#660">}</span></div></code></div><br>This puts all=
 of the iteration logic in the same place: the `for` statement itself. So i=
f you want to see what 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></blockq=
uote></div></div></div></div></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/8ee79066-43c5-4624-8fb5-01172eb36d29%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8ee79066-43c5-4624-8fb5-01172eb36d29=
%40isocpp.org</a>.<br />

------=_Part_1278_2027970891.1469491298078--

------=_Part_1277_712424841.1469491298070--

.
