The first version is reading in all of the lines beforehand building up a temporary list (which given a substantially large file may take a good bit of time and/or memory) then iterating over that list; the while reads one line at a time until the end of file is reached so there's nowhere near as much overhead.
The cake is a lie.
The cake is a lie.
The cake is a lie.
In reply to Re: Why is "for" much slower than "while"?
by Fletch
in thread Why is "for" much slower than "while"?
by di
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |