From 5003865878827317284
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news2.google.com!news.glorb.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Helmut Zeisel <zei2006q1@liwest.at>
Newsgroups: comp.std.c++
Subject: Re: for-else: adding else to for loops
Date: Tue, 18 Aug 2009 12:56:09 CST
Organization: http://groups.google.com
Lines: 22
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <8ca0fe0a-aade-4c5f-89b4-d6dec40675cc@32g2000yqj.googlegroups.com>
References: <5d82cd6c-2a22-4dd7-8c7d-790b579533ea@d15g2000prc.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: Tue, 18 Aug 2009 03:45:36 -0700 (PDT)
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:1306

On Aug 7, 7:56 pm, Jared Grubb <jared.gr...@gmail.com> wrote:

> I've seen examples
> in live code where developers solve this by:
> 1) re-testing the loop condition,
> 2) using an extra flag-variable declared outside of the for loop that
> can be tested after the for loop finished (e.g., put "bool
> success=false" outside the loop in the second example),
> 3) by encapsulating the for-loop in a separate function (the "break"
> becomes "return" and the extra code follows the for loop).

Why don't you use "goto after-else-branch" instead of "break"?

Helmut


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



