Discovering Functions

Learn about the basic concepts of Functions

The role of functions

To understand the importance of functions, let’s refer back to the burrito algorithm.

Press + to interact
Begin
Get out the rice cooker
Fill it with rice
Fill it with water
Cook the rice
Chop the vegetables
Stir-fry the vegetables
Taste-test the vegetables
If the veggies are good
Remove them from the stove
If the veggies aren't good
Add more pepper and spices
If the veggies aren't cooked enough
Keep stir-frying the veggies
Heat the tortilla
Add rice to the tortilla
Add vegetables to the tortilla
Roll tortilla
End

Here’s the same general idea, written in a different way.

Press + to interact
Begin
Cook rice
Stir-fry vegetables
Add fillings
Roll together
End

The first version details all the individual actions that make up the cooking process. The second breaks down the recipe into broader steps and introduces concepts that could be re-used for other dishes as well like cook, stir-fry, add and roll.

Our programs so far ...

Access this course and 1400+ top-rated courses and projects.