--- James Edward Gray II <[EMAIL PROTECTED]> wrote: > On Mar 7, 2004, at 7:07 PM, Stuart White wrote: > > > Ah, so there is a use for the for which is like > > foreach other than a shortcut. Can I do that with > > foreach? I see that what you are describing with > the > > foreach loops above is what was going on with my > > nested foreach loops before. > > I believe this is the remaining source of your > confusion and I bet I > can make it go away by explaining one simple fact: > Perl allows the > words for and foreach to be used interchangeably, > they mean exactly the > same thing. That help? >
Yup. thanks. > >>> next() jumps to the next iteration of the target > >> loop, or the enclosing > >> loop, by default. Consider this example: > >> > >> foreach (1..10) { > >> next if $_ % 2; # skip to the next number, if > this > >> one is odd > >> print "$_\n"; # this prints just even numbers > >> } > >> > > > > That is helpful. Though why would you want to use > > next? Is is just another way to do something? > > It could be sure. There's generally more than one > way to do things, > especially in Perl. In the above example, you could > just put the > print() call inside a conditional. However, there > are times when doing > something without next() would be a lot more work. > My nested for loops > to find prime numbers is probably a decent example > of that. > I see. > Hope that helps. > > James > Thanks all for your patience and assistance. __________________________________ Do you Yahoo!? Yahoo! Search - Find what you’re looking for faster http://search.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>