In an ideal teaching language
If the language directly supports them then the order to teach looping constructs seems simple.
- Infinite loop:
forever
. - Simple finite (bounded) loop:
repeat n times
. - Bounded loops:
for i in list
orfor i = 1...6
(I am not sure which order these two should be in). - Simple unbounded:
while condition
- Complex loops: all the rest.
However often the teaching language does not directly support these. This may be an argument for choosing a different language for teaching programming.
The problems that I am having
(I am teaching in Python).
I was teaching in the order I outlined for an ideal language, but are getting problems.
For an infinite loop we use while True
in Python, however students ask or struggle with this. I can not explain it without explaining while condition
. So pupils have to hold something that they do not understand in their head.
Similar for repeat n times
in Python it is for n in range(5):
, this is a lot to keep in ones head without understanding.
The question
So the question is “what to do?”. Do we start with
- Bounded loops:
for i in list:
- Bounded loops:
for i in range(n):
- Simple unbounded:
while condition:
Or do we do it some other way?