As I have been teaching Python to year 7s this term, as well as my KS2 teaching, it has struck me how many computational concepts I am having to teach, often for the first time for these students. Sometimes this is due to lack of any experiences with coding in the primary years, however, with most students, it appears that they have not delved deeply into the concepts, mastering selection and iteration in different contexts.
Perhaps the main reason to extend block programming in schools beyond the Scratch language, and also possibly into KS3, is to develop these computational concepts that are not clear and easily achieved in MIT’s offering.
One such concept I believe is the ‘else if’ construction…
‘If’ only I could keep it simple
Consider a game of Rock Paper Scissors, which is effectively choosing a random number and displaying an image with the result.
A pupil might come up with this as their solution. It looks great until they run it and never get ‘rock’ as a result.
The second if statement immediately changes the costume, because if ‘handGesture > 20’ then ‘handGesture > 10’ as well.
Or pupils may try to comment on the Score at the end of a game with just ‘if’ statements… Compare the complexity of the working solution, with what a child may first attempt.
What they are looking for is an ‘if’ type statement that, once the first option is chosen, the others are excluded. This is the if…. else if…. else construction.
Nesting ‘if…else’ in Scratch
An alternative approach which achieves this is to nest the ‘if else’ statements. The ‘else if’ works, but this does have its perils.
This example opposite is probably the simplest outcome in Scratch, however, without good understanding from clear teaching or code comprehension exercises, students may become confused when trying to recreate this in their own projects.
For instance, these examples below also work… they may be attempted by pupils who don’t fully understand the concept of nesting to achieve ‘else if’, with statements eliminating conditions as they proceed through the code.
Looking at these examples above…
The first example keeps the order of score statements, however, it requires a Boolean statement to achieve the mid-range.
The second code sample removes the Boolean, however, the order may be confusing for a learner.
The final option works as well, keeping the order of statements correct without Booelan, however the ‘if…else’ statements are nested in a less obvious manner and the operators are in reverse order.
Makecode (not war)
So perhaps a better method of introducing this concept is to use a block coding language which more naturally delivers an else…if statement.
My personal recommendation would be to explore in upper KS2 using Makecode with something like the MicroBit. https://makecode.microbit.org/
The if…else block in Makecode has a + button at the bottom, which quite naturally adds an ‘else if’ segment to the block allowing for more than one condition to be set in the same ‘if’ construction.
Conceptually this is far easier for the pupil, and after completing an unplugged activity and examining some code (using PRIMM) the student will be better prepared.
Making the jump back to Scratch, or on to a text-based language may then prove easier. Once the concept and construction are mastered in a language such as Makecode, the workaround in Scratch becomes far easier to grapple with. Additionally, the ‘if … elif … else’ command in Python become clearer too.