www.digitalmars.com         C & C++   DMDScript  

D - foreach

reply "Matthew Wilson" <dmd synesis.com.au> writes:
Any progress on this. It'd be real nice.

Has the format been decided yet? I would suggest that as well as supporting

char[] s = "Some string";

foreach (c in s)
  c  = c + 2;

it also supports specification of the type of the element, to support
conversions

class Y
{
  void DoSomething()
  {
  }
}

class X
{
  int i;
  Y y;

  operator Y() // I don't know what the syntax for user-defined operator
methods is.
}

X[] arr = new X[10];

foreach (Y y in arr)
  y.DoSomething();


Make sense?
Mar 27 2003
next sibling parent reply "anderson" <anderson badmama.com.au> writes:
"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:b5ul7c$17q2$1 digitaldaemon.com...
 Any progress on this. It'd be real nice.

 Has the format been decided yet? I would suggest that as well as
supporting
 char[] s = "Some string";

 foreach (c in s)
   c  = c + 2;

 it also supports specification of the type of the element, to support
 conversions

 class Y
 {
   void DoSomething()
   {
   }
 }

 class X
 {
   int i;
   Y y;

   operator Y() // I don't know what the syntax for user-defined operator
 methods is.
 }

 X[] arr = new X[10];

 foreach (Y y in arr)
   y.DoSomething();


 Make sense?
Parhaps, foreach could also act like a with startement.... X[] arr = new X[10]; foreach (Y y in arr) .DoSomething(); Of course for nested loops the implicit form could be used.
Mar 27 2003
parent "Jon Allen" <jallen minotstateu.edu> writes:
 foreach (Y y in arr)
   y.DoSomething();


 Make sense?
Sounds yummy to me :-)
 Parhaps, foreach could also act like a with startement....

 X[] arr = new X[10];

 foreach (Y y in arr)
   .DoSomething();

 Of course for nested loops the implicit form could be used.
Special cases are bad, if we did it for foreach should do it for for too, but we can't really, because the c-style for is much to flexible for anything as straightforward as that. Not to mention the ugliness of nested loops. I say we just explicitly write "with" when we want a with.
Mar 27 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
I'm going to do foreach, but the syntax is a bit up in the air right now.

"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:b5ul7c$17q2$1 digitaldaemon.com...
 Any progress on this. It'd be real nice.

 Has the format been decided yet? I would suggest that as well as
supporting
 char[] s = "Some string";

 foreach (c in s)
   c  = c + 2;

 it also supports specification of the type of the element, to support
 conversions

 class Y
 {
   void DoSomething()
   {
   }
 }

 class X
 {
   int i;
   Y y;

   operator Y() // I don't know what the syntax for user-defined operator
 methods is.
 }

 X[] arr = new X[10];

 foreach (Y y in arr)
   y.DoSomething();


 Make sense?
Mar 27 2003