Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flowchart illustration for for loops #815

georgezakinih opened this issue Mar 23, 2020 · 4 comments

Add flowchart illustration for for loops #815

georgezakinih opened this issue Mar 23, 2020 · 4 comments


Copy link

georgezakinih commented Mar 23, 2020

In teaching sequential programming languages, flowcharts are very useful illustration to mimic the step by step instructions as the processor executes them

I suggest adding a flowchart to illustrate how loop works in lesson 4 "Repeating Actions with Loops". I see that flowcharts where used to illustrate "if statements" in lesson 7 "Making choices". The for loop flowchart can further be demonstrated with the print character example.

The for loop flowchart consists of a terminating condition and a body. To keep it simple, the condition can be stated as: "Done with collection iteration", the simplest body would be "Get next item in collection"

I appreciate your comments.

Copy link

ldko commented Mar 26, 2020

Hi George, I think it could be helpful to learners to see a flowchart of a for loop as you suggest. Maybe something akin to the structure of here: The condition "Done with collection iteration?" makes sense to me, or in the example of the print character example, "Processed all characters in word?" . Regarding the body, to me, "Get next item in collection" seems more in line with incrementing the loop variable than being the body. I see the body being more along the lines of "Do task" or in the case of the character example "Print character".

If you find time to submit a pull request for this, we welcome it. Thanks for bringing up this issue for discussion.

Copy link

RaphaelaHeil commented May 18, 2020

I hope it's okay that I am joining this?!
I have created a first version of the suggested flowchart.

Following the existing flowchart in episode 07, I did not include the start/stop terminals however I am not too happy with the way the Yes-arrow runs into nowhere - any thoughts/suggestions?
I also included the assignment "char = next unprocessed character in word", since there is a similar indication in loops_image.png.

Looking forward to hearing your thoughts on this!


(Image is available as svg but can't be attached in that format)

Copy link

ldko commented May 19, 2020

I think it is great you joined this issue @RaphaelaHeil ! I think your image helps to give an idea of a for loop running. Perhaps the yes arrow could go into an "exit loop" or "leave loop" or "resume code after loop"? I'm not sure either :D. I am wondering if @georgezakinih and the other maintainers @maxim-belkin and @annefou have comments about the flowchart. I think in discussing this topic with Maxim he had some concerns the diagram I suggested not correctly indicating how the Python for loop isn't like in some languages and continues until it hits a StopIteration being raised. I think bringing in this detail might be overload at this point in learning though. What do you all think?

Copy link

maxim-belkin commented Jun 5, 2020

Hi all!
Thank you @georgezakinih for the suggestion and @RaphaelaHeil for the work you've done.
(And, of course, thank you @ldko for working on this.)

My apologies to all of you for taking so long to write this response. I have to admit that it took me longer than usual to formulate (for myself) my thoughts on this issue. So, here is what I think:

  1. I like the idea of adding a visual to explain how for-loops work. Personally, visuals helps me a lot when I'm learning new material.
  2. Generally speaking, flowcharts are ideally suited for this purpose.
  3. I like the flowchart by @RaphaelaHeil -- it accurately represents what Python does in a for-loop without going into too much detail.

So, all in all, I'd say that suggested flowchart would definitely improve our lesson.
Now, the question is -- can we make it better? And I think we can. Let me explain.

This flowchart is specific to the first for loop we use in the lesson. To me, this indicates that we have to make sure that

  • our flowchart is tightly linked to the context of the example
  • does not have unexplained components
  • does not confuse learners

The first point above comes from the fact that if I didn't know Python and were to look at the flowchart, I wouldn't know if the keyword is for, foreach, forall, or something like that. I think one way to link flowchart to the context of the example is to show that for loop in the image. It will be also useful to instructors explaining for loops by allowing them to show the for loop and flowchart on one page without going back and forth.

By "unexplained components" I basically meant "Yes" arrow going out from the "processed all characters" -- what happens at the end of that arrow?

Finally, what I'm trying to say in the last point above is that our learners might be very new to programming in Python and we should be careful about using syntax that looks-like Python code but in reality is not. In the proposed flowchart I see couple of such examples: print char and char = ....

I decided that because it took me so long to formulate my thoughts and write this response I had to provide a visual explanation of what I mean by all of the above. So, below are my drafts that, while don't solve all the issues, make a step in that direction.

I suggest we continue the discussion, decide on what should be in the visual, improve it until we all agree and then create a PR. I'd be happy to share originals of my drafts if we decide to use one of them as a starting point.

Again, thank you all for the discussion and apologies for the delay.


for loop in context-01

for loop in context2-01

for loop in context3-01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

4 participants