in case you don't notice my solution is wrong lol.
you don't need any loop statement to solve this problem its a straight forward process, i remembered i used the same technique when converting remaining time to words.
from:
Code:
if ()
else if()
else if()
else if()
else
statements you can change it to
Code:
if()
if()
if()
if()
therefore eliminating the need to use a loop
with functions you can abstract the problem to make it more simple, therefore eliminating the need to do nested if statements.