Computer ScienceComputingHigh schoolKey Stages 4 and 5
How to teach recursion
Recursion is a function calling itself, and every recursive function needs a base case that tells it when to stop. This page explains both, with a free activity where students run recursive code in Python or Java and Sparky asks for the base case instead of fixing it.
Jemel Fanfan | Founding Member at Flint

"My students use Flint to practice coding, receiving instant feedback and tailored support that helps refine their skills at their own pace. This has been particularly effective in addressing individual learning gaps and fostering a growth mindset."
Ali Shameem, Computer Science and Cybersecurity Teacher at Brewster MadridWhy this matters
A student can write the recursive call correctly and still believe the function will stop by itself when it reaches 0. When the code runs, the numbers fall past 0 into negatives and end in a long red error that never mentions a base case. The student guesses at a fix, and the teacher has to wait for the unit test to find out who still thinks the function knows when to stop.
Recursion and the base case
Recursion is a function calling itself to solve a problem made of smaller versions of the same problem. A recursive function has a base case, which ends the recursion, and a recursive case, which calls the function again (MDN).
Without a base case, the calls never end until the language stops them. Recursion in Python ends in a RecursionError when the calls go past Python's maximum depth (Python documentation). Recursion in Java ends in a StackOverflowError, which Java throws when a program recurses too far and overflows the stack (Oracle). AP Computer Science A, which is taught in Java, lists executing recursive methods in its Data Collections unit (College Board).
In the Flint activity, each student writes and runs four recursive functions in Python or Java, from a countdown to fibonacci, and sends each one to Sparky. Unlike a worksheet, Sparky reads the code the student ran and asks about the base case that student wrote, without writing the fix.
Sparky gets Diego to find his own base case
Diego ends up writing his own base case and explaining why fibonacci(35) is slow. Every student gets the same activity, and Sparky's replies depend on the code and answers each student sends.
Diego
Diego
it should stop on its own when n gets to 0 since n keeps getting smaller. but when i ran it, it printed 5 4 3 2 1 0 and then kept going -1 -2 -3 all the way down and then said RecursionError: maximum recursion depth exceeded.
Sparky

Diego

Understanding check
Diego
fibonacci(35) took a few seconds and printed 9227465. i think its slow because the answer is a huge number
Sparky
Diego
every call splits into two more calls so it keeps doubling, and it redoes stuff it already figured outWrote his own base case, then explained why fibonacci is slow
Diego is an example student, and Sparky's replies are shortened.
What Flint did for Diego
- When Diego's countdown ran past 0, Sparky built a call stack from his own code to step through.
- Sparky asked which call should be the last one instead of writing the base case for him.
- When Diego blamed fibonacci's huge answer, Sparky pointed him back to his fast factorial to find the real reason.
A teacher can't do this by hand for 30 students, and Sparky does it in every student's chat.
The activity page shows who still thinks the function stops by itself
While the class works, Needs attention shows the teacher which student is stuck and on which message. After three or more students submit, activity analytics lists what the class explained well, where students went wrong, and a follow-up to practice next.

Example activity page
After a computer science class writes its first recursive functions
The school and students are made up for this page.
Set up the activity for free
Open the recursion activity in Flint's public library, select Use activity to copy it into a free Flint account, and assign it to a class. Students open the code editor with the Write code button under the message box, pick Python or Java, and press Execute to run their code. Java students end their code with a call such as Main.countdown(5); outside the class, because the editor doesn't run main(). A function that never stops prints more than fits in one message, so students send the code and type the error's last line.
For more computer science activities, see Flint for computer science.
Other use cases
See all use cases →World LanguageModern foreign languagesMiddle schoolKey Stage 3

How to teach reflexive verbs in Spanish
Reflexive verbs in Spanish: the pronouns me, te, se, nos, os and se, and where they go. In a free Flint activity, students narrate their morning routine and Sparky turns it into a slide comic, so a missing pronoun shows up as a slide that looks wrong.
English Language ArtsEnglishHigh schoolKey Stages 4 and 5

How to teach rhetorical analysis
How to teach rhetorical analysis: students name the appeals in a narrated ad Sparky makes about their own interest, then check whether its statistic is true. A student who calls the expert's endorsement logos gets sent back to the expert's line, and a student who believes the statistic watches Sparky check it against three sources.
World LanguageModern foreign languagesMiddle schoolKey Stage 3

How to teach ser vs estar
How to teach ser vs estar: ser for who or what something is, estar for how it is and where it is, and why the permanent vs temporary rule breaks. In a free Flint activity, students upload a picture of their pet, describe it in Spanish, and Sparky uses the picture to ask which verb fits.
