Depending on how the 'lines' are indexed, you might have to do new i=max-1.
for () loops are simple, you just need to learn how they work. They consist of three parameters: starting value, condition that dictates when the loop should break and incremental/decremental value.