FOR LOOP moves to top

when I use FOR LOOP in coding, when I update, it automatically changes location. Pls help, how to use for loop.

Its not clear, please provide details.

Sr Description Qty Rate Amount
{{ row.idx }} {{ row.item_code }} - {{ row.description }} {{ row.qty }} {{ row.get_formatted("rate", doc) }} {{ row.get_formatted("amount", doc) }}

Can you please tell me the coding error? Because, if I press update button, FOR Loop will move to top row.