Hacker News new | ask | show | jobs
by tynpeddler 3110 days ago
Say you have 10,000 lines of text, and you want to find the index of the line that contains the 302nd 'U'. You could do this with a while loop, but in the process you would find yourself setting up an index and dutifully incrementing it by 1 to keep track of the line you're currently looking at. A for loop is simpler here.