Fix line num calculation in newchar

Fix PR #8613
That's the new range-based for loop introduced in C++11. It's not just shorter to write, but it's also potentially faster, because the end() value of the loop is guaranteed to be calculated only once. (The compiler often optimizes this in ordinary for loops too, but it isn't guaranteed to do so if end() is complicated.) More on that here: http://www.drdobbs.com/cpp/auto-types-and-range-based-for-statement/232900460