Austin Hastings writes: > The other concern is idiom. Using C<for> suggests "start at the > beginning, continue to the end". OTOH, using C<while> is a little > "weaker" -- "keep doing this until it's time to stop". Obviously they'll > usually be used in the same way: > > for =<> {...} vs. while (<>) {...} > > This seems a subtle concern, and maybe it's just my latent fear of > change making me uncomfortable, but I actually *think* in english -- not > that it does much good -- and this isn't how I think. I think that C<for> reads much better than C<while> for English-ness. Having taught Perl 5 beginners that C<foreach> can be used to iterated over each item in a list, many of them then instinctively try to use the same keyword for iterating over each line in a file. (Which of course works -- albeit inefficiently and umidiomatically -- so they don't bother looking any further.) To me C<for> makes sense when you've got a pile of stuff you're intending to process (such as array items or lines in a file), and C<while> makes sense when you're waiting for a condition (such as the user correctly entering her/his password) and you couldn't possibly know in advance how many times you'll be looping. SmylersThread Previous | Thread Next