Topic: Looping construct with in-the-middle test: do
Author: John McFarlane <john@mcfarlane.name>
Date: Fri, 16 Dec 2016 09:39:11 -0800
Raw View
--94eb2c05aa7647526d0543ca0cd9
Content-Type: text/plain; charset=UTF-8
In the past, I've certainly wanted something a little different than the
control structures we have. What about something simpler that what we have,
equivalent to `for (;;) {}`:
loop {
if (condition) {
continue;
}
// do stuff
if (exit condition) {
break
}
}
? Here, it's up to the user to break out explicitly.
On Fri, Dec 16, 2016, 7:52 AM Alexandre Isoard <alexandre.isoard@gmail.com>
wrote:
>
>
> On Friday, December 16, 2016 at 3:29:02 PM UTC, Nicol Bolas wrote:
>
>
>
> On Friday, December 16, 2016 at 10:10:35 AM UTC-5, alexandr...@gmail.com
> wrote:
>
> Other examples:
>
> Classic for loop:
> for (int i = 0; i < n; ++i) {
> code();
> }
>
> Equivalent to:
> do {
> int i = 0;
> } while (i < n) {
> code();
> ++i;
> }
>
>
> No, that's not equivalent. You explicitly stated that the `do` part was
> executed first, then once for every loop. That will therefore reinitialize
> the `int i` every time through the loop.
>
> Oops. Indeed, I was thinking "static int" all along and that is just plain
> wrong.
>
> Also, the semantic would not match the classical do {} while(); semantic
> which is against what I was aiming for...
>
> That is:
> do {
> bool condition = test();
> } while(condition);
>
> Is currently (and probably forever) incorrect code as the condition
> variable's life-time do not propagate to the test...
>
> So none of these are accurate conversions from `for` to this syntax. And
> even if they were... why would you use them instead of just `for`?
>
> Indeed, they are all wrong, sorry. The only one that would have been
> "useful" would be the reverse for loop with unsigned integers.
> But anyway, that is all incorrect, meaculpa.
>
>
> Overall, this is a bad idea. You have two blocks with a while in the
> middle; by normal C++ rules, that means variables declared in the first
> block are outside the scope of the second. Yet you want to access them
> inside of the second block.
>
> That is indeed one of the (many?) nasty behavior.
>
>
> That's like declaring variables in an `if` block and expecting them to be
> accessible from the `else` block.
>
> That is an exaggerated comparison. For `if` / `else` the semantic does not
> require to execute the `if` part when the `else` part is executed, while in
> this case it always happen.
> But I agree that it would be the only construct that has this unnatural
> bleeding. I expected this proposition to be widely rejected for this exact
> reason.
>
> --
> 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/65ecd66b-aee9-422e-
> 8fa9-ed0ea8e873a7%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/65ecd66b-aee9-422e-8fa9-ed0ea8e873a7%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>
--
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/CABPJVnSLDPA0X7dkxeD_R3-Sc1%2BfaTo7mLvnHqxK33YjBSV-0w%40mail.gmail.com.
--94eb2c05aa7647526d0543ca0cd9
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><p dir=3D"ltr">In the past, I've certainly wanted some=
thing a little different than the control structures we have. What about so=
mething simpler that what we have, equivalent to `for (;;) {}`:</p><p>loop =
{</p><p>=C2=A0 if (condition) {</p><p>=C2=A0=C2=A0=C2=A0 continue;</p><p>=
=C2=A0 }</p><p>=C2=A0 // do stuff</p><p>=C2=A0 if (exit condition) {</p><p>=
=C2=A0=C2=A0=C2=A0 break</p><p>=C2=A0 }<br></p><p>}<br></p>? Here, it's=
up to the user to break out explicitly.<br><div><br><div class=3D"gmail_qu=
ote"><div dir=3D"ltr">On Fri, Dec 16, 2016, 7:52 AM Alexandre Isoard <<a=
href=3D"mailto:alexandre.isoard@gmail.com" target=3D"_blank">alexandre.iso=
ard@gmail.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div d=
ir=3D"ltr" class=3D"m_-2445414151384145276gmail_msg"><br class=3D"m_-244541=
4151384145276gmail_msg"><br class=3D"m_-2445414151384145276gmail_msg">On Fr=
iday, December 16, 2016 at 3:29:02 PM UTC, Nicol Bolas wrote:<blockquote cl=
ass=3D"gmail_quote m_-2445414151384145276gmail_msg" style=3D"margin:0;margi=
n-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr" =
class=3D"m_-2445414151384145276gmail_msg"><br class=3D"m_-24454141513841452=
76gmail_msg"><br class=3D"m_-2445414151384145276gmail_msg">On Friday, Decem=
ber 16, 2016 at 10:10:35 AM UTC-5, <a class=3D"m_-2445414151384145276gmail_=
msg">alexandr...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote m_-24=
45414151384145276gmail_msg" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr" class=3D"m_-244541415138=
4145276gmail_msg">Other examples:<div class=3D"m_-2445414151384145276gmail_=
msg"><br class=3D"m_-2445414151384145276gmail_msg"></div><div class=3D"m_-2=
445414151384145276gmail_msg">Classic for loop:</div><div class=3D"m_-244541=
4151384145276gmail_msg"><div style=3D"background-color:rgb(250,250,250);bor=
der-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:br=
eak-word" class=3D"m_-2445414151384145276gmail_msg"><code class=3D"m_-24454=
14151384145276gmail_msg"><div class=3D"m_-2445414151384145276gmail_msg"><sp=
an style=3D"color:#008" class=3D"m_-2445414151384145276gmail_msg">for</span=
><span style=3D"color:#000" class=3D"m_-2445414151384145276gmail_msg"> </sp=
an><span style=3D"color:#660" class=3D"m_-2445414151384145276gmail_msg">(</=
span><span style=3D"color:#008" class=3D"m_-2445414151384145276gmail_msg">i=
nt</span><span style=3D"color:#000" class=3D"m_-2445414151384145276gmail_ms=
g"> i </span><span style=3D"color:#660" class=3D"m_-2445414151384145276gmai=
l_msg">=3D</span><span style=3D"color:#000" class=3D"m_-2445414151384145276=
gmail_msg"> </span><span style=3D"color:#066" class=3D"m_-24454141513841452=
76gmail_msg">0</span><span style=3D"color:#660" class=3D"m_-244541415138414=
5276gmail_msg">;</span><span style=3D"color:#000" class=3D"m_-2445414151384=
145276gmail_msg"> i </span><span style=3D"color:#660" class=3D"m_-244541415=
1384145276gmail_msg"><</span><span style=3D"color:#000" class=3D"m_-2445=
414151384145276gmail_msg"> n</span><span style=3D"color:#660" class=3D"m_-2=
445414151384145276gmail_msg">;</span><span style=3D"color:#000" class=3D"m_=
-2445414151384145276gmail_msg"> </span><span style=3D"color:#660" class=3D"=
m_-2445414151384145276gmail_msg">++</span><span style=3D"color:#000" class=
=3D"m_-2445414151384145276gmail_msg">i</span><span style=3D"color:#660" cla=
ss=3D"m_-2445414151384145276gmail_msg">)</span><span style=3D"color:#000" c=
lass=3D"m_-2445414151384145276gmail_msg"> </span><span style=3D"color:#660"=
class=3D"m_-2445414151384145276gmail_msg">{</span><span style=3D"color:#00=
0" class=3D"m_-2445414151384145276gmail_msg"><br class=3D"m_-24454141513841=
45276gmail_msg">=C2=A0 code</span><span style=3D"color:#660" class=3D"m_-24=
45414151384145276gmail_msg">();</span><span style=3D"color:#000" class=3D"m=
_-2445414151384145276gmail_msg"><br class=3D"m_-2445414151384145276gmail_ms=
g"></span><span style=3D"color:#660" class=3D"m_-2445414151384145276gmail_m=
sg">}</span><font class=3D"m_-2445414151384145276gmail_msg" color=3D"#00000=
0"></font></div></code></div><br class=3D"m_-2445414151384145276gmail_msg">=
Equivalent to:</div><div class=3D"m_-2445414151384145276gmail_msg"><div sty=
le=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);borde=
r-style:solid;border-width:1px;word-wrap:break-word" class=3D"m_-2445414151=
384145276gmail_msg"><code class=3D"m_-2445414151384145276gmail_msg"><div cl=
ass=3D"m_-2445414151384145276gmail_msg"><span style=3D"color:#008" class=3D=
"m_-2445414151384145276gmail_msg">do</span><span style=3D"color:#000" class=
=3D"m_-2445414151384145276gmail_msg"> </span><span style=3D"color:#660" cla=
ss=3D"m_-2445414151384145276gmail_msg">{</span><span style=3D"color:#000" c=
lass=3D"m_-2445414151384145276gmail_msg"><br class=3D"m_-244541415138414527=
6gmail_msg">=C2=A0 </span><span style=3D"color:#008" class=3D"m_-2445414151=
384145276gmail_msg">int</span><span style=3D"color:#000" class=3D"m_-244541=
4151384145276gmail_msg"> i </span><span style=3D"color:#660" class=3D"m_-24=
45414151384145276gmail_msg">=3D</span><span style=3D"color:#000" class=3D"m=
_-2445414151384145276gmail_msg"> </span><span style=3D"color:#066" class=3D=
"m_-2445414151384145276gmail_msg">0</span><span style=3D"color:#660" class=
=3D"m_-2445414151384145276gmail_msg">;</span><span style=3D"color:#000" cla=
ss=3D"m_-2445414151384145276gmail_msg"><br class=3D"m_-2445414151384145276g=
mail_msg"></span><span style=3D"color:#660" class=3D"m_-2445414151384145276=
gmail_msg">}</span><font class=3D"m_-2445414151384145276gmail_msg" color=3D=
"#000000"><span style=3D"color:#000" class=3D"m_-2445414151384145276gmail_m=
sg"> </span><span style=3D"color:#008" class=3D"m_-2445414151384145276gmail=
_msg">while</span><span style=3D"color:#000" class=3D"m_-244541415138414527=
6gmail_msg"> </span><span style=3D"color:#660" class=3D"m_-2445414151384145=
276gmail_msg">(</span><span style=3D"color:#000" class=3D"m_-24454141513841=
45276gmail_msg">i </span><span style=3D"color:#660" class=3D"m_-24454141513=
84145276gmail_msg"><</span><span style=3D"color:#000" class=3D"m_-244541=
4151384145276gmail_msg"> n</span><span style=3D"color:#660" class=3D"m_-244=
5414151384145276gmail_msg">)</span><span style=3D"color:#000" class=3D"m_-2=
445414151384145276gmail_msg"> </span><span style=3D"color:#660" class=3D"m_=
-2445414151384145276gmail_msg">{</span><span style=3D"color:#000" class=3D"=
m_-2445414151384145276gmail_msg"><br class=3D"m_-2445414151384145276gmail_m=
sg">=C2=A0 code</span><span style=3D"color:#660" class=3D"m_-24454141513841=
45276gmail_msg">();</span><span style=3D"color:#000" class=3D"m_-2445414151=
384145276gmail_msg"><br class=3D"m_-2445414151384145276gmail_msg">=C2=A0 </=
span><span style=3D"color:#660" class=3D"m_-2445414151384145276gmail_msg">+=
+</span><span style=3D"color:#000" class=3D"m_-2445414151384145276gmail_msg=
">i</span><span style=3D"color:#660" class=3D"m_-2445414151384145276gmail_m=
sg">;</span><span style=3D"color:#000" class=3D"m_-2445414151384145276gmail=
_msg"><br class=3D"m_-2445414151384145276gmail_msg"></span><span style=3D"c=
olor:#660" class=3D"m_-2445414151384145276gmail_msg">}</span></font></div><=
/code></div><br class=3D"m_-2445414151384145276gmail_msg"></div></div></blo=
ckquote><div class=3D"m_-2445414151384145276gmail_msg"><br class=3D"m_-2445=
414151384145276gmail_msg">No, that's not equivalent. You explicitly sta=
ted that the `do` part was executed first, then once for every loop. That w=
ill therefore reinitialize the `int i` every time through the loop.<br clas=
s=3D"m_-2445414151384145276gmail_msg"></div></div></blockquote></div><div d=
ir=3D"ltr" class=3D"m_-2445414151384145276gmail_msg"><div class=3D"m_-24454=
14151384145276gmail_msg">Oops. Indeed, I was thinking "static int"=
; all along and that is just plain wrong.</div><div class=3D"m_-24454141513=
84145276gmail_msg"><br class=3D"m_-2445414151384145276gmail_msg"></div><div=
class=3D"m_-2445414151384145276gmail_msg">Also, the semantic would not mat=
ch the classical do {} while(); semantic which is against what I was aiming=
for...</div><div class=3D"m_-2445414151384145276gmail_msg"><br class=3D"m_=
-2445414151384145276gmail_msg"></div><div class=3D"m_-2445414151384145276gm=
ail_msg">That is:</div><div class=3D"m_-2445414151384145276m_-7791486760076=
008313prettyprint m_-2445414151384145276gmail_msg" style=3D"background-colo=
r:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-=
width:1px;word-wrap:break-word"><code class=3D"m_-2445414151384145276m_-779=
1486760076008313prettyprint m_-2445414151384145276gmail_msg"><div class=3D"=
m_-2445414151384145276m_-7791486760076008313subprettyprint m_-2445414151384=
145276gmail_msg"></div></code></div></div><div dir=3D"ltr" class=3D"m_-2445=
414151384145276gmail_msg"><div class=3D"m_-2445414151384145276m_-7791486760=
076008313prettyprint m_-2445414151384145276gmail_msg" style=3D"background-c=
olor:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;bord=
er-width:1px;word-wrap:break-word"><code class=3D"m_-2445414151384145276m_-=
7791486760076008313prettyprint m_-2445414151384145276gmail_msg"><div class=
=3D"m_-2445414151384145276m_-7791486760076008313subprettyprint m_-244541415=
1384145276gmail_msg"><span style=3D"color:#008" class=3D"m_-244541415138414=
5276m_-7791486760076008313styled-by-prettify m_-2445414151384145276gmail_ms=
g">do</span><span style=3D"color:#000" class=3D"m_-2445414151384145276m_-77=
91486760076008313styled-by-prettify m_-2445414151384145276gmail_msg"> </spa=
n><span style=3D"color:#660" class=3D"m_-2445414151384145276m_-779148676007=
6008313styled-by-prettify m_-2445414151384145276gmail_msg">{</span><span st=
yle=3D"color:#000" class=3D"m_-2445414151384145276m_-7791486760076008313sty=
led-by-prettify m_-2445414151384145276gmail_msg"><br class=3D"m_-2445414151=
384145276gmail_msg">=C2=A0 </span><span style=3D"color:#008" class=3D"m_-24=
45414151384145276m_-7791486760076008313styled-by-prettify m_-24454141513841=
45276gmail_msg">bool</span><span style=3D"color:#000" class=3D"m_-244541415=
1384145276m_-7791486760076008313styled-by-prettify m_-2445414151384145276gm=
ail_msg"> condition </span><span style=3D"color:#660" class=3D"m_-244541415=
1384145276m_-7791486760076008313styled-by-prettify m_-2445414151384145276gm=
ail_msg">=3D</span><span style=3D"color:#000" class=3D"m_-24454141513841452=
76m_-7791486760076008313styled-by-prettify m_-2445414151384145276gmail_msg"=
> test</span><span style=3D"color:#660" class=3D"m_-2445414151384145276m_-7=
791486760076008313styled-by-prettify m_-2445414151384145276gmail_msg">();</=
span><span style=3D"color:#000" class=3D"m_-2445414151384145276m_-779148676=
0076008313styled-by-prettify m_-2445414151384145276gmail_msg"><br class=3D"=
m_-2445414151384145276gmail_msg"></span></div></code></div></div><div dir=
=3D"ltr" class=3D"m_-2445414151384145276gmail_msg"><div class=3D"m_-2445414=
151384145276m_-7791486760076008313prettyprint m_-2445414151384145276gmail_m=
sg" style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187=
);border-style:solid;border-width:1px;word-wrap:break-word"><code class=3D"=
m_-2445414151384145276m_-7791486760076008313prettyprint m_-2445414151384145=
276gmail_msg"><div class=3D"m_-2445414151384145276m_-7791486760076008313sub=
prettyprint m_-2445414151384145276gmail_msg"><span style=3D"color:#660" cla=
ss=3D"m_-2445414151384145276m_-7791486760076008313styled-by-prettify m_-244=
5414151384145276gmail_msg">}</span><span style=3D"color:#000" class=3D"m_-2=
445414151384145276m_-7791486760076008313styled-by-prettify m_-2445414151384=
145276gmail_msg"> </span><span style=3D"color:#008" class=3D"m_-24454141513=
84145276m_-7791486760076008313styled-by-prettify m_-2445414151384145276gmai=
l_msg">while</span><span style=3D"color:#660" class=3D"m_-24454141513841452=
76m_-7791486760076008313styled-by-prettify m_-2445414151384145276gmail_msg"=
>(</span><span style=3D"color:#000" class=3D"m_-2445414151384145276m_-77914=
86760076008313styled-by-prettify m_-2445414151384145276gmail_msg">condition=
</span><span style=3D"color:#660" class=3D"m_-2445414151384145276m_-7791486=
760076008313styled-by-prettify m_-2445414151384145276gmail_msg">);</span></=
div></code></div><div class=3D"m_-2445414151384145276gmail_msg"><br class=
=3D"m_-2445414151384145276gmail_msg"></div><div class=3D"m_-244541415138414=
5276gmail_msg">Is currently (and probably forever) incorrect code as the co=
ndition variable's life-time do not propagate to the test...</div></div=
><div dir=3D"ltr" class=3D"m_-2445414151384145276gmail_msg"><div class=3D"m=
_-2445414151384145276gmail_msg"><br class=3D"m_-2445414151384145276gmail_ms=
g"></div><blockquote class=3D"gmail_quote m_-2445414151384145276gmail_msg" =
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr" class=3D"m_-2445414151384145276gmail_msg"><div class=
=3D"m_-2445414151384145276gmail_msg">So none of these are accurate conversi=
ons from `for` to this syntax. And even if they were... why would you use t=
hem instead of just `for`?</div></div></blockquote></div><div dir=3D"ltr" c=
lass=3D"m_-2445414151384145276gmail_msg"><div class=3D"m_-24454141513841452=
76gmail_msg">Indeed, they are all wrong, sorry. The only one that would hav=
e been "useful" would be the reverse for loop with unsigned integ=
ers.</div><div class=3D"m_-2445414151384145276gmail_msg">But anyway, that i=
s all incorrect, meaculpa.</div></div><div dir=3D"ltr" class=3D"m_-24454141=
51384145276gmail_msg"><div class=3D"m_-2445414151384145276gmail_msg">=C2=A0=
</div><blockquote class=3D"gmail_quote m_-2445414151384145276gmail_msg" sty=
le=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr" class=3D"m_-2445414151384145276gmail_msg">Overall, this=
is a bad idea. You have two blocks with a while in the middle; by normal C=
++ rules, that means variables declared in the first block are outside the =
scope of the second. Yet you want to access them inside of the second block=
..</div></blockquote></div><div dir=3D"ltr" class=3D"m_-2445414151384145276g=
mail_msg"><div class=3D"m_-2445414151384145276gmail_msg">That is indeed one=
of the (many?) nasty behavior.</div></div><div dir=3D"ltr" class=3D"m_-244=
5414151384145276gmail_msg"><div class=3D"m_-2445414151384145276gmail_msg">=
=C2=A0</div><blockquote class=3D"gmail_quote m_-2445414151384145276gmail_ms=
g" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-l=
eft:1ex"><div dir=3D"ltr" class=3D"m_-2445414151384145276gmail_msg">That=
9;s like declaring variables in an `if` block and expecting them to be acce=
ssible from the `else` block.<br class=3D"m_-2445414151384145276gmail_msg">=
</div></blockquote></div><div dir=3D"ltr" class=3D"m_-2445414151384145276gm=
ail_msg"><div class=3D"m_-2445414151384145276gmail_msg">That is an exaggera=
ted comparison. For `if` / `else` the semantic does not require to execute =
the `if` part when the `else` part is executed, while in this case it alway=
s happen.</div><div class=3D"m_-2445414151384145276gmail_msg">But I agree t=
hat it would be the only construct that has this unnatural bleeding. I expe=
cted this proposition to be widely rejected for this exact reason.</div></d=
iv>
<p class=3D"m_-2445414151384145276gmail_msg"></p>
-- <br class=3D"m_-2445414151384145276gmail_msg">
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br class=3D"m_-244541=
4151384145276gmail_msg">
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" class=3D"m_=
-2445414151384145276gmail_msg" target=3D"_blank">std-proposals+unsubscribe@=
<wbr>isocpp.org</a>.<br class=3D"m_-2445414151384145276gmail_msg">
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" class=3D"m_-2445414151384145276gmail_msg" target=3D"_blank">std-propo=
sals@isocpp.org</a>.<br class=3D"m_-2445414151384145276gmail_msg">
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/65ecd66b-aee9-422e-8fa9-ed0ea8e873a7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" class=3D"m_-244541=
4151384145276gmail_msg" target=3D"_blank">https://groups.google.com/a/<wbr>=
isocpp.org/d/msgid/std-<wbr>proposals/65ecd66b-aee9-422e-<wbr>8fa9-ed0ea8e8=
73a7%40isocpp.org</a><wbr>.<br class=3D"m_-2445414151384145276gmail_msg">
</blockquote></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CABPJVnSLDPA0X7dkxeD_R3-Sc1%2BfaTo7mL=
vnHqxK33YjBSV-0w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CABPJVnSLDPA0X7=
dkxeD_R3-Sc1%2BfaTo7mLvnHqxK33YjBSV-0w%40mail.gmail.com</a>.<br />
--94eb2c05aa7647526d0543ca0cd9--
.
Author: "D. B." <db0451@gmail.com>
Date: Fri, 16 Dec 2016 17:43:14 +0000
Raw View
--001a11c39b22c110b00543ca1a83
Content-Type: text/plain; charset=UTF-8
I've never understood why people want a new keyword, or even feel the need
to do the absurd *#define ever*, merely because they don't like typing the
perfectly logical *while (true)* for some reason.
--
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/CACGiwhEr_mpPhsA%2BLqz7f5rmmXok-OBZ9%3Dm-w78GLoUjm71tEA%40mail.gmail.com.
--001a11c39b22c110b00543ca1a83
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I've never understood why people want a new keyword, o=
r even feel the need to do the absurd <i>#define ever</i>, merely because t=
hey don't like typing the perfectly logical <i>while (true)</i> for som=
e reason.<br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CACGiwhEr_mpPhsA%2BLqz7f5rmmXok-OBZ9%=
3Dm-w78GLoUjm71tEA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhEr_mpP=
hsA%2BLqz7f5rmmXok-OBZ9%3Dm-w78GLoUjm71tEA%40mail.gmail.com</a>.<br />
--001a11c39b22c110b00543ca1a83--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 16 Dec 2016 10:30:59 -0800 (PST)
Raw View
------=_Part_800_1891313791.1481913059735
Content-Type: multipart/alternative;
boundary="----=_Part_801_985590491.1481913059736"
------=_Part_801_985590491.1481913059736
Content-Type: text/plain; charset=UTF-8
On Friday, December 16, 2016 at 12:39:14 PM UTC-5, John McFarlane wrote:
>
> In the past, I've certainly wanted something a little different than the
> control structures we have. What about something simpler that what we have,
> equivalent to `for (;;) {}`:
>
> loop {
>
> if (condition) {
>
> continue;
>
> }
>
> // do stuff
>
> if (exit condition) {
>
> break
>
> }
>
> }
> ? Here, it's up to the user to break out explicitly.
>
We already have a proposal on something like that: P0082
<http://wg21.link/P0082>.
>
> On Fri, Dec 16, 2016, 7:52 AM Alexandre Isoard <alexandr...@gmail.com
> <javascript:>> wrote:
>
>>
>>
>> On Friday, December 16, 2016 at 3:29:02 PM UTC, Nicol Bolas wrote:
>>>
>>>
>>>
>>> On Friday, December 16, 2016 at 10:10:35 AM UTC-5, alexandr...@gmail.com
>>> wrote:
>>>>
>>>> Other examples:
>>>>
>>>> Classic for loop:
>>>> for (int i = 0; i < n; ++i) {
>>>> code();
>>>> }
>>>>
>>>> Equivalent to:
>>>> do {
>>>> int i = 0;
>>>> } while (i < n) {
>>>> code();
>>>> ++i;
>>>> }
>>>>
>>>>
>>> No, that's not equivalent. You explicitly stated that the `do` part was
>>> executed first, then once for every loop. That will therefore reinitialize
>>> the `int i` every time through the loop.
>>>
>> Oops. Indeed, I was thinking "static int" all along and that is just
>> plain wrong.
>>
>> Also, the semantic would not match the classical do {} while(); semantic
>> which is against what I was aiming for...
>>
>> That is:
>> do {
>> bool condition = test();
>> } while(condition);
>>
>> Is currently (and probably forever) incorrect code as the condition
>> variable's life-time do not propagate to the test...
>>
>> So none of these are accurate conversions from `for` to this syntax. And
>>> even if they were... why would you use them instead of just `for`?
>>>
>> Indeed, they are all wrong, sorry. The only one that would have been
>> "useful" would be the reverse for loop with unsigned integers.
>> But anyway, that is all incorrect, meaculpa.
>>
>>
>>> Overall, this is a bad idea. You have two blocks with a while in the
>>> middle; by normal C++ rules, that means variables declared in the first
>>> block are outside the scope of the second. Yet you want to access them
>>> inside of the second block.
>>>
>> That is indeed one of the (many?) nasty behavior.
>>
>>
>>> That's like declaring variables in an `if` block and expecting them to
>>> be accessible from the `else` block.
>>>
>> That is an exaggerated comparison. For `if` / `else` the semantic does
>> not require to execute the `if` part when the `else` part is executed,
>> while in this case it always happen.
>> But I agree that it would be the only construct that has this unnatural
>> bleeding. I expected this proposition to be widely rejected for this exact
>> reason.
>>
>> --
>> 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-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/65ecd66b-aee9-422e-8fa9-ed0ea8e873a7%40isocpp.org
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/65ecd66b-aee9-422e-8fa9-ed0ea8e873a7%40isocpp.org?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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/3b8fd8c1-f960-4473-b9cb-224cfa89088e%40isocpp.org.
------=_Part_801_985590491.1481913059736
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, December 16, 2016 at 12:39:14 PM UTC-5,=
John McFarlane wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><p dir=3D"ltr">In the past, I've certainly wanted something a =
little different than the control structures we have. What about something =
simpler that what we have, equivalent to `for (;;) {}`:</p><p>loop {</p><p>=
=C2=A0 if (condition) {</p><p>=C2=A0=C2=A0=C2=A0 continue;</p><p>=C2=A0 }</=
p><p>=C2=A0 // do stuff</p><p>=C2=A0 if (exit condition) {</p><p>=C2=A0=C2=
=A0=C2=A0 break</p><p>=C2=A0 }<br></p><p>}<br></p>? Here, it's up to th=
e user to break out explicitly.<br></div></blockquote><div><br>We already h=
ave a proposal on something like that: <a href=3D"http://wg21.link/P0082">P=
0082</a>.<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
dir=3D"ltr"><div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Fri, De=
c 16, 2016, 7:52 AM Alexandre Isoard <<a href=3D"javascript:" target=3D"=
_blank" gdf-obfuscated-mailto=3D"Go76q9hyCgAJ" rel=3D"nofollow" onmousedown=
=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D=
'javascript:';return true;">alexandr...@gmail.com</a>> wrote:<br=
></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-=
left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><br>On Friday, D=
ecember 16, 2016 at 3:29:02 PM UTC, Nicol Bolas wrote:<blockquote class=3D"=
gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid=
;padding-left:1ex"><div dir=3D"ltr"><br><br>On Friday, December 16, 2016 at=
10:10:35 AM UTC-5, <a>alexandr...@gmail.com</a> wrote:<blockquote class=3D=
"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc soli=
d;padding-left:1ex"><div dir=3D"ltr">Other examples:<div><br></div><div>Cla=
ssic for loop:</div><div><div style=3D"background-color:rgb(250,250,250);bo=
rder-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:b=
reak-word"><code><div><span style=3D"color:#008">for</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">(</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"> i =
</span><span style=3D"color:#660"><</span><span style=3D"color:#000"> n<=
/span><span style=3D"color:#660">;</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">++</span><span style=3D"color:#000">i</span><sp=
an style=3D"color:#660">)</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 code</span=
><span style=3D"color:#660">();</span><span style=3D"color:#000"><br></span=
><span style=3D"color:#660">}</span><font color=3D"#000000"></font></div></=
code></div><br>Equivalent to:</div><div><div style=3D"background-color:rgb(=
250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:=
1px;word-wrap:break-word"><code><div><span style=3D"color:#008">do</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span s=
tyle=3D"color:#000"><br>=C2=A0 </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"><br></span><span st=
yle=3D"color:#660">}</span><font color=3D"#000000"><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">while</span><span style=3D"color:#000=
"> </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"> n</=
span><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 co=
de</span><span style=3D"color:#660">();</span><span style=3D"color:#000"><b=
r>=C2=A0 </span><span style=3D"color:#660">++</span><span style=3D"color:#0=
00">i</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br></span><span style=3D"color:#660">}</span></font></div></code></div><br>=
</div></div></blockquote><div><br>No, that's not equivalent. You explic=
itly stated that the `do` part was executed first, then once for every loop=
.. That will therefore reinitialize the `int i` every time through the loop.=
<br></div></div></blockquote></div><div dir=3D"ltr"><div>Oops. Indeed, I wa=
s thinking "static int" all along and that is just plain wrong.</=
div><div><br></div><div>Also, the semantic would not match the classical do=
{} while(); semantic which is against what I was aiming for...</div><div><=
br></div><div>That is:</div><div style=3D"background-color:rgb(250,250,250)=
;border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wra=
p:break-word"><code><div></div></code></div></div><div dir=3D"ltr"><div sty=
le=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);borde=
r-style:solid;border-width:1px;word-wrap:break-word"><code><div><span style=
=3D"color:#008">do</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 </span><span styl=
e=3D"color:#008">bool</span><span style=3D"color:#000"> condition </span><s=
pan style=3D"color:#660">=3D</span><span style=3D"color:#000"> test</span><=
span style=3D"color:#660">();</span><span style=3D"color:#000"><br></span><=
/div></code></div></div><div dir=3D"ltr"><div style=3D"background-color:rgb=
(250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width=
:1px;word-wrap:break-word"><code><div><span style=3D"color:#660">}</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">while</span><sp=
an style=3D"color:#660">(</span><span style=3D"color:#000">condition</span>=
<span style=3D"color:#660">);</span></div></code></div><div><br></div><div>=
Is currently (and probably forever) incorrect code as the condition variabl=
e's life-time do not propagate to the test...</div></div><div dir=3D"lt=
r"><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0;margi=
n-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">=
<div>So none of these are accurate conversions from `for` to this syntax. A=
nd even if they were... why would you use them instead of just `for`?</div>=
</div></blockquote></div><div dir=3D"ltr"><div>Indeed, they are all wrong, =
sorry. The only one that would have been "useful" would be the re=
verse for loop with unsigned integers.</div><div>But anyway, that is all in=
correct, meaculpa.</div></div><div dir=3D"ltr"><div>=C2=A0</div><blockquote=
class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px =
#ccc solid;padding-left:1ex"><div dir=3D"ltr">Overall, this is a bad idea. =
You have two blocks with a while in the middle; by normal C++ rules, that m=
eans variables declared in the first block are outside the scope of the sec=
ond. Yet you want to access them inside of the second block.</div></blockqu=
ote></div><div dir=3D"ltr"><div>That is indeed one of the (many?) nasty beh=
avior.</div></div><div dir=3D"ltr"><div>=C2=A0</div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr">That's like declaring variables in an=
`if` block and expecting them to be accessible from the `else` block.<br><=
/div></blockquote></div><div dir=3D"ltr"><div>That is an exaggerated compar=
ison. For `if` / `else` the semantic does not require to execute the `if` p=
art when the `else` part is executed, while in this case it always happen.<=
/div><div>But I agree that it would be the only construct that has this unn=
atural bleeding. I expected this proposition to be widely rejected for this=
exact reason.</div></div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
Go76q9hyCgAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"Go76q9hyCgAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@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/65ecd66b-aee9-422e-8fa9-ed0ea8e873a7%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/65ecd66b-aee9-422e-8fa9-ed0ea8e873a7%40i=
socpp.org?utm_medium\x3demail\x26utm_source\x3dfooter';return true;" on=
click=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/st=
d-proposals/65ecd66b-aee9-422e-8fa9-ed0ea8e873a7%40isocpp.org?utm_medium\x3=
demail\x26utm_source\x3dfooter';return true;">https://groups.google.com=
/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/65ecd66b-aee9-422e-<wbr>8fa9-=
ed0ea8e873a7%40isocpp.org</a><wbr>.<br>
</blockquote></div></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" 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/3b8fd8c1-f960-4473-b9cb-224cfa89088e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3b8fd8c1-f960-4473-b9cb-224cfa89088e=
%40isocpp.org</a>.<br />
------=_Part_801_985590491.1481913059736--
------=_Part_800_1891313791.1481913059735--
.