One of Scratch’s most notable and useful features is its ability to execute multiple blocks of code simultaneously.
Share this step
One of Scratch’s most notable and useful features is its ability to execute multiple blocks of code simultaneously. This means that the computer doesn’t need to wait for one code block to finish running before it executes the next block.
This is known as concurrency. When you use Scratch you don’t need to worry about the order of the code blocks executing, you can just assume that they will all run at the same time.
Here’s an example of a programme displaying such concurrency:
When this programme is run, both blocks of code are executed simultaneously. This causes the sprite they are attached to to switch between saying “On” and “Off” every half a second.
Most text-based programming languages do not allow the programmer to execute multiple parts of their programme in parallel with such ease. For this reason, it is necessary for students that are new to such languages to learn to rethink how such problems can be tackled.
An example of concurrency
A student who is starting to learn Python might try and create the above Scratch programme like this:
This can sometimes be a struggle for students to understand, so it is an important concept to tackle fairly early on when they transition to writing programmes in a text-based language.
Are there any other examples you can use with learners to introduce the concept of concurrency in Python?