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.
The text was updated successfully, but these errors were encountered:
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: https://www.rff.com/flowchart_structure_for_loop.png? 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.
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)
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?
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:
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.
Generally speaking, flowcharts are ideally suited for this purpose.
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.