Topic: Concerns about N3587 "For Loop Exit Strategies


Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sat, 20 Apr 2013 03:24:21 -0700 (PDT)
Raw View
------=_Part_62_450457.1366453461068
Content-Type: text/plain; charset=ISO-8859-1



The proposal N3587 does not provide better syntax. It looks at the follwing
"ugly" code:
something_t last; // Extra construction here.
for (auto& i : c)
{
if (some_condition(i))
{
last = i; // Extra copy here
goto EARLY; }
do_something(i);
}
do_stuff();
goto DONE;
EARLY:
do_something_else(last);
DONE:

and states that new syntax is needed. But the above loop can be easily
re-written using better forms:
(1)
bool ok = true;
for (auto& i : c)
{
    if (some_condition(i))
    {
        ok = true;
        do_something_else(i);
        break;
    }
    do_something(i);
}
if (ok)
{
    do_stuff();
}

(2)
for (auto& i : c)
{
    if (some_condition(i))
    {
        do_something_else(i);
        go EARLY;
    }
    do_something(i);
}
do_stuff();
EARLY:;

The proposal goes ahead and offers nee syntax:
if for (auto& i : c)
{
    if (some_condition(i)) break;
    do_something(i);
}
{
    do_stuff(); // normal termination
}
else
{
    do_something_else(i); // early exit
}

It does not look better than the above written two pieces of code.
Besides it may be confusing if the loop code uses more space:
the code for normal termination can be easily misinterpreted.

--

---
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_62_450457.1366453461068
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<p>The proposal N3587 does not provide better syntax. It looks at the follw=
ing "ugly" code:<br>something_t last; // Extra construction here.<br>for (a=
uto&amp; i : c)<br>{<br>if (some_condition(i))<br>{<br>last =3D i; // Extra=
 copy here<br>goto EARLY; }<br>do_something(i);<br>}<br>do_stuff();<br>goto=
 DONE;<br>EARLY:<br>do_something_else(last);<br>DONE:</p><p>and states that=
 new syntax is needed. But the above loop can be easily re-written using be=
tter forms:<br>(1)<br>bool ok =3D true;<br>for (auto&amp; i : c)<br>{<br>&n=
bsp;&nbsp;&nbsp; if (some_condition(i))<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D true;<br>&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp; do_something_else(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; do_somethi=
ng(i);<br>}<br>if (ok)<br>{<br>&nbsp;&nbsp;&nbsp; do_stuff();<br>}</p><p>(2=
)<br>for (auto&amp; i : c)<br>{<br>&nbsp;&nbsp;&nbsp; if (some_condition(i)=
)<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_something_else(i);<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; go EARLY;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp=
;&nbsp;&nbsp; do_something(i);<br>}<br>do_stuff();<br>EARLY:;</p><p>The pro=
posal goes ahead and offers nee syntax:<br>if for (auto&amp; i : c)<br>{<br=
>&nbsp;&nbsp;&nbsp; if (some_condition(i)) break;<br>&nbsp;&nbsp;&nbsp; do_=
something(i);<br>}<br>{<br>&nbsp;&nbsp;&nbsp; do_stuff(); // normal termina=
tion<br>}<br>else<br>{<br>&nbsp;&nbsp;&nbsp; do_something_else(i); // early=
 exit<br>}</p><p>It does not look better than the above written two pieces =
of code.<br>Besides it may be confusing if the loop code uses more space:<b=
r>the code for normal termination can be easily misinterpreted.<br></p>

<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_62_450457.1366453461068--

.


Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sat, 20 Apr 2013 03:27:24 -0700 (PDT)
Raw View
------=_Part_479_32071295.1366453644629
Content-Type: text/plain; charset=ISO-8859-1



The proposal N3587 does not provide better syntax. It looks at the follwing
"ugly" code:
something_t last; // Extra construction here.
for (auto& i : c)
{
if (some_condition(i))
{
last = i; // Extra copy here
goto EARLY; }
do_something(i);
}
do_stuff();
goto DONE;
EARLY:
do_something_else(last);
DONE:

and states that new syntax is needed. But the above loop can be easily
re-written using better forms:
(1)
bool ok = true;
for (auto& i : c)
{
    if (some_condition(i))
    {
        ok = false;
        do_something_else(i);
        break;
    }
    do_something(i);
}
if (ok)
{
    do_stuff();
}

(2)
for (auto& i : c)
{
    if (some_condition(i))
    {
        do_something_else(i);
        go EARLY;
    }
    do_something(i);
}
do_stuff();
EARLY:;

The proposal goes ahead and offers nee syntax:
if for (auto& i : c)
{
    if (some_condition(i)) break;
    do_something(i);
}
{
    do_stuff(); // normal termination
}
else
{
    do_something_else(i); // early exit
}

It does not look better than the above written two pieces of code.
Besides it may be confusing if the loop code uses more space:
the code for normal termination can be easily misinterpreted.

--

---
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_479_32071295.1366453644629
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<p>The proposal N3587 does not provide better syntax. It looks at the follw=
ing "ugly" code:<br>something_t last; // Extra construction here.<br>for (a=
uto&amp; i : c)<br>{<br>if (some_condition(i))<br>{<br>last =3D i; // Extra=
 copy here<br>goto EARLY; }<br>do_something(i);<br>}<br>do_stuff();<br>goto=
 DONE;<br>EARLY:<br>do_something_else(last);<br>DONE:</p><p>and states that=
 new syntax is needed. But the above loop can be easily re-written using be=
tter forms:<br>(1)<br>bool ok =3D true;<br>for (auto&amp; i : c)<br>{<br>&n=
bsp;&nbsp;&nbsp; if (some_condition(i))<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D false;<br>&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; do_something_else(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; do_someth=
ing(i);<br>}<br>if (ok)<br>{<br>&nbsp;&nbsp;&nbsp; do_stuff();<br>}</p><p>(=
2)<br>for (auto&amp; i : c)<br>{<br>&nbsp;&nbsp;&nbsp; if (some_condition(i=
))<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_something_else(i);<br>&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; go EARLY;<br>&nbsp;&nbsp;&nbsp; }<br>&nbs=
p;&nbsp;&nbsp; do_something(i);<br>}<br>do_stuff();<br>EARLY:;</p><p>The pr=
oposal goes ahead and offers nee syntax:<br>if for (auto&amp; i : c)<br>{<b=
r>&nbsp;&nbsp;&nbsp; if (some_condition(i)) break;<br>&nbsp;&nbsp;&nbsp; do=
_something(i);<br>}<br>{<br>&nbsp;&nbsp;&nbsp; do_stuff(); // normal termin=
ation<br>}<br>else<br>{<br>&nbsp;&nbsp;&nbsp; do_something_else(i); // earl=
y exit<br>}</p><p>It does not look better than the above written two pieces=
 of code.<br>Besides it may be confusing if the loop code uses more space:<=
br>the code for normal termination can be easily misinterpreted.<br></p>

<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_479_32071295.1366453644629--

.


Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sat, 20 Apr 2013 03:30:06 -0700 (PDT)
Raw View
------=_Part_432_13807154.1366453806238
Content-Type: text/plain; charset=ISO-8859-1

The proposal N3587 does not provide better syntax. It looks at the
following "ugly" code:
something_t last; // Extra construction here.
for (auto& i : c)
{
    if (some_condition(i))
    {
          last = i; // Extra copy here
           goto EARLY;
     }
     do_something(i);
}
do_stuff();
goto DONE;
EARLY:
do_something_else(last);
DONE:


and states that new syntax is needed. But the above loop can be easily
re-written using better forms:
(1)
bool ok = true;
for (auto& i : c)
{
    if (some_condition(i))
    {
        ok = false;
        do_something_else(i);
        break;
    }
    do_something(i);
}
if (ok)
{
    do_stuff();
}

(2)
for (auto& i : c)
{
    if (some_condition(i))
    {
        do_something_else(i);
        go EARLY;
    }
    do_something(i);
}
do_stuff();
EARLY:;

The proposal goes ahead and offers new syntax:
if for (auto& i : c)
{
    if (some_condition(i)) break;
    do_something(i);
}
{
    do_stuff(); // normal termination
}
else
{
    do_something_else(i); // early exit
}

It does not look better than the above written two pieces of code.
Besides it may be confusing if the loop code uses more space:
the code for normal termination can be easily misinterpreted.




--

---
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_432_13807154.1366453806238
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>The proposal N3587 does not provide better syntax. It looks at the fol=
lowing "ugly" code:<br>something_t last; // Extra construction here.<br>for=
 (auto&amp; i : c)<br>{<br>&nbsp;&nbsp;&nbsp; if (some_condition(i))<br>&nb=
sp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
 last =3D i; // Extra copy here<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp; goto EARLY; </div><div>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&=
nbsp;&nbsp;&nbsp;&nbsp; do_something(i);<br>}<br>do_stuff();<br>goto DONE;<=
br>EARLY:<br>do_something_else(last);<br>DONE:</div><div>&nbsp;</div><p>and=
 states that new syntax is needed. But the above loop can be easily re-writ=
ten using better forms:<br>(1)<br>bool ok =3D true;<br>for (auto&amp; i : c=
)<br>{<br>&nbsp;&nbsp;&nbsp; if (some_condition(i))<br>&nbsp;&nbsp;&nbsp; {=
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D false;<br>&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_something_else(i);<br>&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbs=
p; do_something(i);<br>}<br>if (ok)<br>{<br>&nbsp;&nbsp;&nbsp; do_stuff();<=
br>}</p><p>(2)<br>for (auto&amp; i : c)<br>{<br>&nbsp;&nbsp;&nbsp; if (some=
_condition(i))<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_something_else(i);<=
br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; go EARLY;<br>&nbsp;&nbsp;&nbs=
p; }<br>&nbsp;&nbsp;&nbsp; do_something(i);<br>}<br>do_stuff();<br>EARLY:;<=
/p><p>The proposal goes ahead and offers new syntax:<br>if for (auto&amp; i=
 : c)<br>{<br>&nbsp;&nbsp;&nbsp; if (some_condition(i)) break;<br>&nbsp;&nb=
sp;&nbsp; do_something(i);<br>}<br>{<br>&nbsp;&nbsp;&nbsp; do_stuff(); // n=
ormal termination<br>}<br>else<br>{<br>&nbsp;&nbsp;&nbsp; do_something_else=
(i); // early exit<br>}</p><p>It does not look better than the above writte=
n two pieces of code.<br>Besides it may be confusing if the loop code uses =
more space:<br>the code for normal termination can be easily misinterpreted=
..</p><p><br>&nbsp;</p>

<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_432_13807154.1366453806238--

.


Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sat, 20 Apr 2013 03:31:51 -0700 (PDT)
Raw View
------=_Part_459_10976649.1366453911335
Content-Type: text/plain; charset=ISO-8859-1



The proposal N3587 does not provide better syntax. It looks at the
following "ugly" code:

something_t last; // Extra construction here.
for (auto& i : c)
{
    if (some_condition(i))
    {
        last = i; // Extra copy here
        goto EARLY;
    }
    do_something(i);
}
do_stuff();
goto DONE;
EARLY:
do_something_else(last);
DONE:

and states that new syntax is needed. But the above loop can be easily
re-written using better forms:
(1)
bool ok = true;
for (auto& i : c)
{
    if (some_condition(i))
    {
        ok = false;
        do_something_else(i);
        break;
    }
    do_something(i);
}
if (ok)
{
    do_stuff();
}

(2)
for (auto& i : c)
{
    if (some_condition(i))
    {
        do_something_else(i);
        go EARLY;
    }
    do_something(i);
}
do_stuff();
EARLY:;

The proposal goes ahead and offers new syntax:
if for (auto& i : c)
{
    if (some_condition(i)) break;
    do_something(i);
}
{
    do_stuff(); // normal termination
}
else
{
    do_something_else(i); // early exit
}

It does not look better than the above written two pieces of code.
Besides it may be confusing if the loop code uses more space:
the code for normal termination can be easily misinterpreted.




--

---
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_459_10976649.1366453911335
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<p>The proposal N3587 does not provide better syntax. It looks at the follo=
wing "ugly" code:</p><p>something_t last; // Extra construction here.<br>fo=
r (auto&amp; i : c)<br>{<br>&nbsp;&nbsp;&nbsp; if (some_condition(i))<br>&n=
bsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; last =3D i=
; // Extra copy here<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto EAR=
LY; <br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; do_something(i);<br>}<br=
>do_stuff();<br>goto DONE;<br>EARLY:<br>do_something_else(last);<br>DONE:</=
p><p>and states that new syntax is needed. But the above loop can be easily=
 re-written using better forms:<br>(1)<br>bool ok =3D true;<br>for (auto&am=
p; i : c)<br>{<br>&nbsp;&nbsp;&nbsp; if (some_condition(i))<br>&nbsp;&nbsp;=
&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D false;<br>&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_something_else(i);<br>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&n=
bsp;&nbsp; do_something(i);<br>}<br>if (ok)<br>{<br>&nbsp;&nbsp;&nbsp; do_s=
tuff();<br>}</p><p>(2)<br>for (auto&amp; i : c)<br>{<br>&nbsp;&nbsp;&nbsp; =
if (some_condition(i))<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; do_something_e=
lse(i);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; go EARLY;<br>&nbsp;&n=
bsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; do_something(i);<br>}<br>do_stuff();<br>=
EARLY:;</p><p>The proposal goes ahead and offers new syntax:<br>if for (aut=
o&amp; i : c)<br>{<br>&nbsp;&nbsp;&nbsp; if (some_condition(i)) break;<br>&=
nbsp;&nbsp;&nbsp; do_something(i);<br>}<br>{<br>&nbsp;&nbsp;&nbsp; do_stuff=
(); // normal termination<br>}<br>else<br>{<br>&nbsp;&nbsp;&nbsp; do_someth=
ing_else(i); // early exit<br>}</p><p>It does not look better than the abov=
e written two pieces of code.<br>Besides it may be confusing if the loop co=
de uses more space:<br>the code for normal termination can be easily misint=
erpreted.</p><p><br>&nbsp;</p>

<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_459_10976649.1366453911335--

.