Question about for each loop

Question about for each loop

I have a database with following structure:

Form1

Name     Quantity       Flag
Name1      30             True
Name2       14            False
...

The Flag Field will be True if the Quantity is the largest.

When I add a new incident the script should check the Quantity if the new one is larger than the previous, then the previous Flag should be False while the new one will be True. 

In this case a "for loop" with index should be convenient. Please any one give me a hint! Thanks!