From 1434890860566975819
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!news.glorb.com!news.alt.net!frodo.cs.rpi.edu!not-for-mail
From: Hyman Rosen <hyrosen@mail.com>
Newsgroups: comp.std.c++
Subject: Re: for-else: adding else to for loops
Date: Mon, 17 Aug 2009 13:18:48 CST
Organization: unknown
Lines: 31
Sender: cppmods@cs.rpi.edu
Approved: stephen.clamage@sun.com
Message-ID: <dqXhm.138643$BP6.80666@newsfe24.iad>
References: <5d82cd6c-2a22-4dd7-8c7d-790b579533ea@d15g2000prc.googlegroups.com>
  <9e9c2ca5-78eb-460c-adec-2ec051c54210@r18g2000yqd.googlegroups.com>
  <E1ihm.95676$BP6.35009@newsfe24.iad>
  <b3293cf8-8b06-4660-9581-50cadc471a3b@a13g2000yqc.googlegroups.com>
NNTP-Posting-Host: netlab.cs.rpi.edu
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
To: (Usenet)
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
X-Original-Date: Sun, 16 Aug 2009 13:33:58 -0400
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Xref: g2news2.google.com comp.std.c++:1305

James Kanze wrote:
> But throwing in an else without knowing what the "if" is
> definitely destroys the readability.  You repeat the test or use
> the added boolean variable so that the reader can see what the
> test is---otherwise, he's fully in the dark.

A language construct has a defined meaning. Why would a
reader be in the dark about it? My suggestion to augment
loops was
      for (init; test; next) SL or SO and SA
      while (test) SL or SO and SA
      do SL while(test); and SA
where a missing 'or' or 'and' part is taken to be there
with a null statement. SO is executed if 'test' is false
the first time it is evaluated. SA is executed if 'test'
is ever false when evaluated. A 'break' in SL, SO, or SA
moves control past the entire construct. Variables in the
'init' statement are in scope in SO and SA. Because of the
semantics of the 'or' and 'and' parts, execution of SO
falls into execution of SA, which is a nice touch.

This cleanly distinguishes between loops having empty
ranges, loops exhausting their ranges, and loops exited
early. What's dark about it?

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



