From 1632839177538614391
X-Google-Thread: 7894ca11fe,d47b345505a72a70
X-Google-Attributes: gid7894ca11fe,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news1.google.com!newsfeed.stanford.edu!news.kjsl.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Jared Grubb <jared.grubb@gmail.com>
Newsgroups: comp.std.c++
Subject: Re: for-else: adding else to for loops
Date: Tue, 11 Aug 2009 14:06:10 CST
Organization: http://groups.google.com
Lines: 39
Sender: cppmods@cs.rpi.edu
Approved: austern@google.com
Message-ID: <84af1815-994d-48d6-9c07-c8965bba0d01@b25g2000prb.googlegroups.com>
References: <5d82cd6c-2a22-4dd7-8c7d-790b579533ea@d15g2000prc.googlegroups.com>
 <memo.20090807224336.1608A@brangdon.cix.compulink.co.uk>
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: Mon, 10 Aug 2009 10:54:02 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:1256

On Aug 7, 5:20 pm, brang...@cix.co.uk (Dave Harris) wrote:
> jared.gr...@gmail.com (Jared Grubb) wrote (abridged):
>
> > In Python, loops can have an else clause; the else clause gets
> >executed when the loop condition fails (but not when the loop
> >is exited via a break, return, or exception).
>
> As it happens, a similar suggestion was made in this group on the 30th
> June, by Doug Van Natter. It was pointed out then that the proposed
> syntax would break existing code that preceded the for-loop with an
> if-statement.

Thanks for the pointer. I figured someone would have asked before, but
it's one of those things that are hard to construct a search for
("for" and "else" being such common words).

> In any case, I don't think there is much support for extending the
> control constructs, as we've managed to get on so well for so long
> without them. You point out yourself three ways to write the code. A
> goto-statement will sometimes work too. So the benefit is marginal, and
> strictly a "programming in the small" affair.

Ah, that's a good point and not easily solvable. It is a rare control
flow, but the alternatives are much harder to read -- and it's not a
hard flow to squeeze into the assembly (but neither is multiple-level
break, as someone else pointed out).

I just thought I'd ask. Once you've seen the flow, it's hard to get
out of your head when a use for it pops up!

Jared


--
[ 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                      ]



