in reply to Interesting Use for "state" Variables
The D language has a nice pragmatic variation on the foreach loop.
Written this way, c takes on each of the values in the array a in turn:
char[] a; ... foreach (char c; a) { ... }
Written this way, the same thing happens, but also i takes on the index of the value also:
char[] a; ... foreach (int i, char c; a)
I don't think there's any possibility of getting that into 5.12 (nor even Perl 6 at this late stage), but it one of those few features of other languages I miss when I'm writing Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Interesting Use for "state" Variables
by massa (Hermit) on Mar 10, 2009 at 02:53 UTC | |
by BrowserUk (Patriarch) on Mar 10, 2009 at 03:46 UTC | |
|
Re^2: Interesting Use for "state" Variables
by eyepopslikeamosquito (Archbishop) on Mar 10, 2009 at 15:44 UTC | |
by BrowserUk (Patriarch) on Mar 10, 2009 at 20:23 UTC |