1 min readJun 17, 2019
I follow the classic teaching approach here with loops and invariants. It has less moving pieces, less code, easier to follow through in your head. Tail recursion is indeed equivalent, but you have to teach people first how to reason about recursive functions, which is one of the harder concepts in computer science.