You might want to consider using an array of fields by using the hierarchical naming convention i.e field.0, field.1, field.2 etc...
Then you can just get the sum of "field". For a sum, as "totalAmount" implies, the order of execution is irrelevant.
J-