# BrainFuck part 11 - Iterative and recursive ways

DPAmar

1,665 views

## Welcome!

Welcome to this new playground about the BF language. Make sure you already read

- Getting started with BrainFuck
- BrainFuck part 2 - Working with arrays
- BrainFuck part 3 - Write a BF interpreter in BF
- BrainFuck part 4 - Advanced maths
- BrainFuck part 5 - Math sequences
- BrainFuck part 6 - 16-bit integers
- BrainFuck part 7 - Quine (+ some non-BF quine theory)
- BrainFuck part 8 - JS/C#/BF Multi quine
- BrainFuck part 9 - Sort arrays with Bubble and QuickSort
- BrainFuck part 10 - RPN calc tool

playgrounds if you didn't already !

The goal of this playground is to compare different ways to implement recursion based on a very common example: factorial

It may be hard to understand how we can define a recursion in a language that does not even allow functions. But functions are just one way to implement recurion.

Actually the main difference between recursion and iteration is : in order to solve a given problem

- the iterative way solves the problem, starting from a simple version and getting closer to the solution by incrementing the initial result
- the recursive way solves the problem, defining the solution as a function of solutions to the same problem for smaller instances

It can be proven that both ways are equivalent, and that an algorithm that uses one of these can be re-implemented using the other one.

## Factorial function

The factorial function `!`

is recursively defined by

- factorial(0) = 0! = 1
- factorial(n) = n! = n x factorial(n-1)

Let's see different ways to implement this function using BF

Create your playground on Tech.io

This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.

Suggested playgrounds

Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!

JOIN US ON DISCORD Online Participants