From -1636247306628916913
X-Google-Thread: 7894ca11fe,d47b345505a72a70
X-Google-Attributes: gid7894ca11fe,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII
Path: g2news2.google.com!news2.google.com!news.glorb.com!news2.glorb.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: darkmx <micael.dark@gmail.com>
Newsgroups: comp.std.c++
Subject: Re: for-else: adding else to for loops
Date: Sun,  9 Aug 2009 09:51:09 CST
Organization: http://groups.google.com
Lines: 49
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <738e6f62-3d38-45f1-8ec1-a91cb8ee5721@m20g2000vbp.googlegroups.com>
References: <5d82cd6c-2a22-4dd7-8c7d-790b579533ea@d15g2000prc.googlegroups.com>
  <bc630f0f-6189-418e-917e-77328a08dbe6@d34g2000vbm.googlegroups.com>
  <aba05dcd-8b4f-496d-a6cb-2058ea237ff6@f10g2000vbf.googlegroups.com>
  <bd4b8740-9b3a-484e-94dd-362cd9ff8c9e@j9g2000vbp.googlegroups.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset=ISO-8859-1
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Sun, 9 Aug 2009 07:42:17 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:1244

On 8 ago, 22:00, Howard Hinnant <howard.hinn...@gmail.com> wrote:
> On Aug 8, 11:54 am, Mathias Gaunard <loufo...@gmail.com> wrote:
>
> > On 8 ao�t, 00:24, Howard Hinnant <howard.hinn...@gmail.com> wrote:
>
> > > for (auto i : seq)
> > > {
> > >    cout << ", " << i;
> > >    for one   {cout << "The only number is " << i << '\n';}
> > >    for first {cout << "The numbers are " << i;}
> > >    for last  {cout << " and " << i << '\n';}}
>
> > > for none {cout << "There are no numbers\n";}
>
> > I would have expected cout << ", " << i to be executed in all cases
> > here, not only in the non-one, non-first and non-last cases.
>
> What would the use case look like?
>
> -Howard
>
> --
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-...@netlab.cs.rpi.edu]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html                     ]

it's not a matter of a use case, but a matter of syntax, I agree with
Mathias

I would prefer

for (auto i : seq) {
     for one { cout << "The only number is " << i << '\n'; }
     for first { cout << "The numbers are " << i; }
     for last { cout << " and " << i << '\n'; }
     for others { cout << ", " << i; }
}
for none {cout << "There are no numbers\n";}

and a naked cout << ", " << i; being executed every iteration


-- 
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



