return
in a function means you are leaving the function immediately and returning to the place where you call it.
So you should use return
when you are 100% certain that you wanna exit the function immediately.
In your example, I think you don’t want to exit the function until you get the final value of c, so you should place the return
outside of the loop.