# Question about the formula Mosh used

**URL:** <https://forum.codewithmosh.com/t/question-about-the-formula-mosh-used/21787>\
**Category:** Java\
**Created:** [July 30, 2023, 8:42pm UTC](https://forum.codewithmosh.com/t/question-about-the-formula-mosh-used/21787 "2023-07-30T20:42:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conan\_7x](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/conan_7x/32/6764_2.png) [@Conan\_7x](https://forum.codewithmosh.com/u/Conan_7x)\
**Post date:** [July 30, 2023, 8:42pm UTC](https://forum.codewithmosh.com/t/question-about-the-formula-mosh-used/21787/1 "2023-07-30T20:42:26Z")

</div>

In ‘Java Part 1’ in the ‘clean code’ section ep 7 minute (1:10), he used a formula to calculate the remaining balance. Can’t we subtract the payment from the principal directly in a for loop? Like why we need a formula ?

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [July 31, 2023, 4:23pm UTC](https://forum.codewithmosh.com/t/question-about-the-formula-mosh-used/21787/2 "2023-07-31T16:23:20Z")

</div>

Hi,  
Welcome in here.  
First thank you to provide clear information on the part you are talking about.  
I did not take that course so I don’t know the code itself, but from what you say, I see there is a matter of loop and formula.

I’d say the formula is a nicer solution for :

- **Readability** : It is simpler to read one line and it is cleaner.
- **Performance** : If you can compute something directly without looping through a data set, this is preferred.

Now I may be off, but that’s my guess for now.

Good luck.

---

<div class="post-metadata">

**Author:** ![Conan\_7x](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/conan_7x/32/6764_2.png) [@Conan\_7x](https://forum.codewithmosh.com/u/Conan_7x)\
**Post date:** [August 22, 2023, 1:00am UTC](https://forum.codewithmosh.com/t/question-about-the-formula-mosh-used/21787/3 "2023-08-22T01:00:55Z")

</div>

Hi,  
You’re welcome! And thank you for replying fast.  
You have a valid point about what you said, that’s a good way of thinking.  
Appreciate your effort both ways.
