# 5,000 Folders Deep: Recursion or a Loop?

Keep the folder tool working on a folder thousands of levels deep, where recursion runs out of call stack: why a bigger limit and a plain loop both fall short, how a loop with a pile of its own does the job, and how to choose between recursion and a loop for any task.

![Cheat sheet: 5,000 Folders Deep: Recursion or a Loop?](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/a24ed3c36ff0432fbd8a04ea9ce21b3c.webp)

- Category: Data Structures
- Level: Journeyman
- Tags: Call Stack (data-structures), data structures, Iterative Solution, Recursion (data-structures), Stack Overflow
- Updated: November 3, 2026

Source: https://www.ask-codey.com/cheat-sheets/ds-recursion-vs-loops-cheat-sheet
