What are recursive calls?

A recursive call is when a function calls itself to solve part of a problem, like a never-ending game of tag.

Imagine you're stacking cups on top of each other. You start with one cup, then add another, and keep going until the stack is as tall as you are. Each time you put a new cup on top, it's like saying, "I'll do this again, but one step closer to my goal."

Like a Bouncing Ball

Think of a ball bouncing down a staircase. When it hits a step, it bounces up to the next one, and keeps doing that until it reaches the top. Each bounce is a recursive call, the ball doesn’t stop until it has gone through every step.

The Secret Ingredient

The reason this works is because each time the function calls itself, it's working on a slightly smaller version of the problem. It’s like having a team of helpers who each do a little bit of work and pass the task along, just like you passing your cup-stacking job to a friend who then passes it to another.

So whether it's stacking cups or bouncing down stairs, recursive calls help us solve big problems by breaking them into smaller, easier steps.

Take the quiz →

Examples

  1. A child asks, 'Why is the sky blue?' and keeps asking the same question until they get tired.
  2. Counting down from 10 to 0 by saying each number out loud one at a time.
  3. Folding a piece of paper in half repeatedly until it becomes too thick to fold again.

Ask a question

See also

Discussion

Recent activity