in reply to best way to write code
Besides the answers to the specific example, whenever you code you should avoid typing the same thing twice. In your example, you format numbers by using the same statement, although each uses a different variable. That's a lot of repeated code that you have to maintain in parallel. If you get it wrong the first time, you have update every place you copy-and-pasted it.
There are various looping constructs that will do this, and the other replies show some of those.
|
|---|