Re: [Feature Request] "first:" "last:" sections in a "foreach" block

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Joep (Staat_at_DeStoep.nl)
Date: 04/05/04


Date: Tue, 6 Apr 2004 00:06:21 +0200

IMHO

foreach means foreach means foreach, so for each item of a collection of
items do this. I would not like to see a switch inside the loop that test
for the first or the last or whichever item. It conflicts with what I
learned long time ago about loop-unrolling and its effect.

Instead, I would like to state foreach item in this (not that) collection do
this, this collection excluding the first and last item for example, in
other words, I would like to be able to more precisely define the items for
which I want some code to execute. It could be that I want to execute this
for every other item and that for all the others.

What about something along these lines where I would be able to define a
part of the collection of items? A bit like string.substring and similar
constructs.

foreach(item in items[2,8])

or

foreach(item in items[2,])

or like the Python splice thingy?

The suggestion I like, meaning a way to more precisely define which items to
execute code for. Syntax and semantics are another thing.

Can't this be done already I wonder...



Relevant Pages

  • Re: [Feature Request] "first:" "last:" sections in a "foreach" block
    ... > foreach means foreach means foreach, so for each item of a collection of ... It could be that I want to execute this ... Order returned by an enumerator is only statically defined during the ... Syntax and semantics are another thing. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [Feature Request] "first:" "last:" sections in a "foreach" block
    ... > I would think that by the definition of foreach, the language construct ... You don't need to know the ordinality though - you only need to know ... and the "last" bit you just execute ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Why doesnt foreach return a value
    ... the body of the foreach command never is executed. ... proc test { ... foreach a $l {incr itemcount} ... with foreach returning a value (or if the body doesn't execute) ...
    (comp.lang.tcl)
  • Re: threads
    ... This creates a single thread to execute the block. ... $threads->create and async has to do with whether you're compfortable ... foreach { ...
    (perl.beginners)
  • Re: Count Lines in (Huge) Text Files
    ... A few years ago, I was doing some high-throughput disk stuff and my recollection is that I found the same thing you did: larger buffers only helped up to about 8K or so, and past that any improvement was minimal. ... me that with appropriate settings for its buffer, it should perform better, since it ought to be optimized for line-based i/o. ... Assuming what's hurting you in the explicit forloop is the retrieval of the data and not the counter increment, the above should perform basically as well as a plain foreach() loop. ...
    (microsoft.public.dotnet.languages.csharp)