Why is this line of code in the loop (Scripting API example script)?

My question regards the 130197-dropdown.jpg
Why is the underlined line of code in the loop?

Doesn’t it set m_Index to the same number each time (as m_Messages.Count does not change) it is run in the loop?

Why not place is out of the loop after or before it?

(I do understand that it’s purpose is to get the last valid index of the List)

Seems unnecessary yes, it could be outside of the foreach loop.