[Swift-devel] iterate behaviour round II

Mihael Hategan hategan at mcs.anl.gov
Wed Aug 3 12:19:28 CDT 2011


On Wed, 2011-08-03 at 17:20 +0200, Ben Clifford wrote:
> On Aug 3, 2011, at 4:23 PM, Michael Wilde wrote:
> 
> > 
> > To start a parallel thread here: how feasible is it (within the
> write-once variable model and scope-creation semantics that iterate
> uses) to provide the 3 C iteration statements with syntax and
> semantics as close to C as possible?
> 
> the independent-iterations use cases are pretty well covered by
> foreach, I think. (where each iteration is independent of other
> iterations)

The dependent iterations are also covered by foreach, and you can't
deadlock as easily as you can in the iterate case:
int a[]; a[0] = 10;
foreach v, k in a {
  if (v > 1) {
    a[k + 1] = v - 1;
  }
}

Though now you could equally do:
int a[auto]; a << 10;
foreach v in a {
  if (v > 1) { a << v - 1; }
}




More information about the Swift-devel mailing list