I would do this using a variety of grounded approaches that many others have already published ...
... however, just for completeness, it's worth noting that you could do a loop if you want. Look at cursors and while loops in books online to see some examples.
Just please don't fall into the trap of using cursors like so many newbies. They have their uses, but if used incorrectly, they can be terrible - almost always the best way to do things.
source share