2009/5/25 sanket vaidya <sanket.vai...@patni.com>: > What is the difference between the 'for' & 'foreach' loops?
There is none. http://perldoc.perl.org/perlsyn.html#Foreach-Loops : "The foreach keyword is actually a synonym for the for keyword, so you can use foreach for readability or for for brevity. (Or because the Bourne shell is more familiar to you than csh, so writing for comes more naturally.)" > I know that they can be used interchangeably then what is the purpose of > keeping them > separate? People come into Perl from different backgrounds, for some, Perl's for (@array) is known as 'foreach' while for is idiomatic as 'for (i = 0; i < something; i++)' (aka C-style for loop), so Perl cater to both tastes, and offer both syntaxes. I, for one, use for only if I want to use a C-style loop, and foreach otherwise, since this, IMO, gives better clarity of my meaning. Perl gives you the freedom to use your own convention. -- Erez http://twitter.com/erez :: we have nothing to lose but our metaphors. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/