http://qs321.pair.com?node_id=817634


in reply to Why is "for" much slower than "while"?

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.