From 7934463443847727219
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: brangdon@cix.co.uk (Dave Harris)
Newsgroups: comp.std.c++
Subject: Re: for-else: adding else to for loops
Date: Fri,  7 Aug 2009 18:20:24 CST
Organization: unknown
Lines: 27
Sender: cppmods@cs.rpi.edu
Approved: austern@google.com
Message-ID: <memo.20090807224336.1608A@brangdon.cix.compulink.co.uk>
References: <5d82cd6c-2a22-4dd7-8c7d-790b579533ea@d15g2000prc.googlegroups.com>
Reply-To: brangdon@cix.co.uk
NNTP-Posting-Host: netlab.cs.rpi.edu
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Fri, 7 Aug 2009 22:43 +0100 (BST)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:1237

jared.grubb@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.

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.

Finally, you may find that closures enable you to encapsulate unusual
control situations in libraries.

-- Dave Harris, Nottingham, UK.

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



