One Level of Indentation per Method
Each method should do one thing at one level of abstraction — nested control structures are a sign to extract a method.
Why this matters
Every extra level of nesting is a cognitive tax. When a method has a loop inside an if inside another loop, you have to hold three contexts in your head at once just to understand the innermost line. Flatten the nesting and you turn one complex function into several simple, independently testable pieces.
Code Challenge
Study the messy code, try to refactor it, then reveal the clean version.
💡Key takeaway
If you need to indent a second time inside a method, stop and extract a helper. The helper name becomes free documentation, and each piece is testable on its own.
🔧 Some exercises may still have errors. If something seems wrong, use the Feedback button (bottom-right of the page) to report it — it helps us fix it fast.
Hint: If you need to indent twice, you need a new method. The second level of indentation is a method waiting to be named.
✗ Your version