Key Concepts

Review core concepts you need to learn to master this subject

Base Case of a Recursive Function

function countdown(value) if value is negative or zero print "done" otherwise if value is greater than zero print value call countdown with (value-1)

A recursive function should have a base case with a condition that stops the function from recursing indefinitely. In the example, the base case is a condition evaluating a negative or zero value to be true.

Recursion: Conceptual
Lesson 1 of 1
  1. 1
    You’ve heard about a trendy new spot that sells fruit sandwiches. What are fruit sandwiches? You have no idea, but you’re eager to find out! Sadly, when you arrive at the store, the line is out t…
  2. 2
    Recursion is a strategy for solving problems by defining the problem in terms of itself. For example, to sum the elements of a list we would take the first element and add it to the **sum of t…
  3. 3
    A recursive approach requires the function invoking itself with different arguments. How does the computer keep track of the various arguments and different function invocations if it’s the sa…
  4. 4
    Recursion has two fundamental aspects: the base case and the recursive step. When using iteration, we rely on a counting variable and a boolean condition. For example, when iterating through the …

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo