SPUG: English-speak about Perl-speak "for" loops

jerry gay jerry.gay at gmail.com
Mon Sep 18 09:51:59 PDT 2006


On 9/15/06, Michael R. Wolf <MichaelRWolf at att.net> wrote:
> I've started seeing more code that uses 'for' for both kinds of loops.
>
>  for(init; entry-condition; iteration) { block }
>  for loop-variable (list) { block }
>
> I know it doesn't confuse the compiler to use 'for' or 'foreach' in either
> case, but it sure does make it harder to speak about.  For that reason, I
> always used to write (and speak) "for" to refer to the C-style 'for' loop
> and "foreach" to refer to the other one.
>
> If you use "for" for both Perl-speak styles, how do you English-speak about
> it to avoid ambiguity?
>
firstly, i never write 'foreach' in perl code. it's not worth the four
extra characters, as 'for' is enough to tell the compiler to do the
right thing.

in order to distinguish them when using english, i relate c-style
'for' to 'while', which is what perl relates it to internally anyway.
perl-style 'for' is the same as map in void context, with syntax
that's arguably easier on the eyes.

looking forward to perl6, 'for' can only be used for perl-style 'for'
loops. in order to express a c-style loop, you must use the 'loop'
keyword. as perl-style looping is far more common in perl code than is
c-style looping, and fewer characters are required to express the more
common case, it is said that this syntax is properly huffmanized. i
think perl6 gets this right.
~jerry


More information about the spug-list mailing list