Flow Chart For a 'for' Loop In Python

In summary, the person is trying to create a flow chart to help them understand and remember their code, but is not sure how to start or where to start. They have searched for information on the internet, but are not sure if there is a general way to do flow charts or if it is up to the person who designs the program. They are also not sure what to include in the flow charts, or how to represent them.
  • #36
symbolipoint said:
I found only one reference in my search online through search engines. That one I later reported did show something like I expected: the hexagonal lengthened shape, one of the first things taught upon being introduced to FOR loop. I did not look much further after finding that one particular online reference, but I know it was in at least one old textbook.
You can find it at any of these (search 'preparation' in your browser when it's displaying the page):
https://www.rff.com/flowchart_shapes.php
https://www.smartdraw.com/flowchart/flowchart-symbols.htm
https://www.gliffy.com/blog/understanding-flowchart-symbols
https://www4.uwsp.edu/geo/faculty/gmartin/geog476/lecture/flowchart_symbols.html
https://en.wikipedia.org/wiki/Flowchart
 
Technology news on Phys.org
  • #37
That "smartdraw" was the one I showed in my post #31 after I said, "still looking...". That much satisfied me for the time.
 
  • #38
symbolipoint said:
That "smartdraw" was the one I showed in my post #31 after I said, "still looking...". That much satisfied me for the time.
Is the difference between the preparation box and the more common rectangular process box reasonably clear to you at present? [In a (not perfectly accurate) nutshell: preparation box is for 'fixed-overhead prerequisite' necessary to do prior to getting useful work done; rectangular process box is for elements and/or composites of the useful work.]
 
  • #39
sysprog said:
Is the difference between the preparation box and the more common rectangular process box reasonably clear to you at present? [In a (not perfectly accurate) nutshell: preparation box is for 'fixed-overhead prerequisite' necessary to do prior to getting useful work done; rectangular process box is for elements and/or composites of the useful work.]
No; not really too clear.

The hexagonal box is specifically the one I know to show the start of a loop, whether of FOR, or WHILE, or DO. The precise condition or range of numbers is shown inside this hexagonal box. Other instructions are then shown inside other symbolic figures. Often the programmer or student would put algebraic and arithmetic steps or other kinds of instructions inside a rectangle, depending what kind or how much detail is inside the loop.
 
  • Like
Likes sysprog
  • #40
First to all, thank for the resource info and comments. More that I was anticipating to be honest, but very informative.

Mark44 said:
From post #1:
A question you should ask yourself is"why draw a flow chart?"
As @.Scott pointed out, flow charts were used before programming languages came along. Many textbooks for programming languages don't even bother with flow charts, but use pseudocode instead. Here's a wikipedia article on pseudocode, with examples in several styles: https://en.wikipedia.org/wiki/Pseudocode

I have read about psudocode and seen it in quite a few textbook, honestly I am more a visual person in terms of learning. And when thinking of how to approch a coding issue I find it easier to draw a flowchart out and go from there. Overtime I suppose I will go the other way, but for now as coding is farily new to me, I find the approach easier.
 
  • Like
Likes sysprog
  • #41
sysprog said:
Isn't your one page constraint arbitrary? Aren't some processes more complicated than others? Why should a description of something extremely complicated have to be confined to a same-size descriptor space as the description of something that is not nearly as complicated?
It's human. One page flowchart is like the 10 minute attention span for spoken monologues.

Earlier I mentioned putting a man on the moon. You could have countless pages of flowcharts for that. Nobody would read them.

One page flowcharts lead to decomposition as an analysis strategy. Each box in the first flowchart leads to a full page flowchart of its own, and each of those to more detailed, and so on. It treats the complex topic as a hierarchy, rather than a linear sequential machine.
 
  • Like
Likes Klystron, symbolipoint, jedishrfu and 1 other person
  • #42
anorlunda said:
It's human. One page flowchart is like the 10 minute attention span for spoken monologues.

Earlier I mentioned putting a man on the moon. You could have countless pages of flowcharts for that. Nobody would read them.

One page flowcharts lead to decomposition as an analysis strategy. Each box in the first flowchart leads to a full page flowchart of its own, and each of those to more detailed, and so on. It treats the complex topic as a hierarchy, rather than a linear sequential machine.
That seems reasonable to me.
 
  • Like
Likes jedishrfu
  • #43
Folks really hated big multi-page flowcharts with little connectors to send you elsewhere.

The preference was if it had to be big then make it into a wallchart.

Top-down programming encouraged this kind of one page flowcharting too.

Many early FORTRAN or COBOL programs weren't necessarily very large (well FORTRAN anyway) as programmers got smart and created tons of reusable library code that you could call. This in turn made the flowcharts arguably smaller since each call became a small box with the subroutine name listed.

And then we did away with flowcharts when structured programming (SP) took over, then OO replaced SP and then automated commenting assists of Eclipse etal... and now the current obfuscation style of coding sans comments... where we are smart enough to know what the other programmer did.
 
Last edited:
  • Like
Likes sysprog and Taylor_1989
  • #44
Taylor_1989 said:
honestly I am more a visual person in terms of learning. And when thinking of how to approch a coding issue I find it easier to draw a flowchart out and go from there. Overtime I suppose I will go the other way, but for now as coding is farily new to me, I find the approach easier.
The use of a flowchart is meant to appeal to that "visual" way of thinking. One builds his flowchart and can then also fill-in as many or all the steps in it, even to the extent of putting in code lines ; and then translating this into a sequence of code becomes very easy. The flowchart serves as a map of where the program (in that portion which the flowchart represents) is going. This helps you think as you develop this part of the program.
 
  • Like
Likes Klystron, jedishrfu, sysprog and 1 other person
  • #45
  • Like
  • Informative
Likes sysprog, QuantumQuest and Taylor_1989
  • #46
The most learning and deep understanding of algorithms that I ever got was from reading the pseudo code in Donald Knuth's famous books. For example, a Shell Sort in 2/3 of one page. A flowchart of that would have been harder to understand.
 
  • Like
Likes Klystron, QuantumQuest, Taylor_1989 and 2 others
  • #47
anorlunda said:
The most learning and deep understanding of algorithms that I ever got was from reading the pseudo code in Donald Knuth's famous books. For example, a Shell Sort in 2/3 of one page. A flowchart of that would have been harder to understand.
Always great to see yet another affirmation of that Computer Science Archon, Professor Donald Knuth.
 
  • Like
Likes Klystron, QuantumQuest and jedishrfu
  • #49
symbolipoint said:
No; not really too clear.

The hexagonal box is specifically the one I know to show the start of a loop, whether of FOR, or WHILE, or DO. The precise condition or range of numbers is shown inside this hexagonal box. Other instructions are then shown inside other symbolic figures. Often the programmer or student would put algebraic and arithmetic steps or other kinds of instructions inside a rectangle, depending what kind or how much detail is inside the loop.
It seems to me that you've got it more clearly than you're advertising, and I find that to be A-OK; whence I say to thee, inquiritor, go thou forward. 😉
 
  • #50
anorlunda said:
The most learning and deep understanding of algorithms that I ever got was from reading the pseudo code in Donald Knuth's famous books. For example, a Shell Sort in 2/3 of one page. A flowchart of that would have been harder to understand.

May I ask what books? Would these books be good for someone who is new to programing?
 
  • #51
The Art of Computer Programming by Donald Knuth

https://en.m.wikipedia.org/wiki/The_Art_of_Computer_Programming
These are classics in the field though not everyone owns a copy. They are akin to an encyclopedia of algorithms and as such take some skill and effort to understand not necessarily a good fit for a newbie programmer.

I considered getting a copy but when i saw it coming out in fascicles decided to wait until it was finished. I am still waiting since 1982, it isn't finished and I imagine granddaughter will just have to wait too.
 
  • Like
Likes sysprog, Taylor_1989, QuantumQuest and 1 other person
  • #52
I don't use flowcharts that much but that is because I've finished learning how to use python and don't need them anymore. But, back when I was still learning python they were persistent on flowcharts being used as it was easier to understand the code. The way I learned it was that parallelograms are a input or output, rectangles are a processes, ellipses are start or end, and diamonds are a decision or check whether a condition is met. I wouldn't stress about flowcharts because when you finish learning it no one uses it seriously.
 
  • Like
Likes Taylor_1989
  • #53
jedishrfu said:
The Art of Computer Programming by Donald Knuth

https://en.m.wikipedia.org/wiki/The_Art_of_Computer_Programming
These are classics in the field though not everyone owns a copy. They akin to an encyclopedia of algorithms and as such take some skill and effort to understand not necessarily a good fit for a newbie programmer.

I considered getting a copy but when i saw it coming out in fascicles decided to wait until it was finished. I am still waiting since 1982, it isn't finished and I imagine granddaughter will just have to wait too.
Professor Donald Knuth is a man the praises regarding whom I cannot sing highly enough. Maybe his pipe organ (yes, everyone, he explains why it has to be a real pipe organ) can sing that high, but I can't. May all that is good be presented to that great man. And oh yeah when you use ##\TeX## you're using that man's code. He wrote it.
 
  • Like
Likes Klystron and Taylor_1989
  • #54
At one of my old jobs, we bought a program (AllClear) that converted psuedocode into a flowchart, but after a couple of months, it became clear that the pseudocode was easier to follow than the flowchart, and the flowcharts were abandoned.

As for Python using a list for a counter, it's not clear with 3.0 and later versions what happens in range(). In Python 2.7, xrange() was used to iterate a counter, not produce a list, unlike range(), but Python 3.0 deprecated xrange(), and I'm not sure if Python doesn't optimize range() into xrange() depending on how it's used.
 
Last edited:
  • #55
My understanding is that range() is dynamic in this respect and similar to xrange() returning an iterator that generates the next number in sequence whereas the old range() generated a list, taking up a fair amount of memory, that was then iterated over.

https://www.pythoncentral.io/pythons-range-function-explained/
So range() became deprecated and xrange() became the new range() in python3.
 
  • Like
Likes Taylor_1989 and sysprog
  • #56
rcgldr said:
At one of my old jobs, we bought a program that converted psuedocode into a flowchart, but after a couple of months, it became clear that the pseudocode was easier to follow than the flowchart, and the flowcharts were abandoned.

As for Python using a list for a counter, it's not clear with 3.0 and later versions what happens in range(). In Python 2.7, xrange() was used to iterate a counter, not produce a list, unlike range(), but Python 3.0 deprecated xrange(), and I'm not sure if Python doesn't optimize range() into xrange() depending on how it's used.
Yes, that's true -- it was a problem regarding memory pre-allocation versus ad hoc dynamic allocation -- now it's dynamic-only ...
 
  • #57
jedishrfu said:
My understanding is that range() is dynamic in this respect and similar to xrange() returning an iterator that generates the next number in sequence whereas the old range() generated a list, taking up a fair amount of memory, that was then iterated over.

https://www.pythoncentral.io/pythons-range-function-explained/
So range() became deprecated and xrange() became the new range() in python3.
I agree with what Sifu Jedi said.
 
  • #58
I made a glaring error in a post in response to @.Scott.
sysprog said:
You could wire the plug-board on a card duplicating machine to allow that, but how would you get, say, an IBM model 29 keypunch machine to do that? It not only doesn't detect which corner is cut, but also as far as I know, it has no capability to read anything on a card, except if you wrap the card around the program drum to be used as a program card, and in that case it could only heed the codes specific to that keypunch machine; not duplicate the card.
This is wrong. It completely ignores the read station on the Model 29. If, for example, you made an error on a single column of a card, say column 51, and didn't notice until you had typed all the way through column 71, you could feed the next blank card, the hit the reg (register) key, which would advance the prior card to the read station, and position the new card at the punch station. Then you could hit and hold the dup key to duplicate the first 50 characters, then type the corrected character for column 51. and then hit and hold the dup key for the rest of the remaining non-incorrect characters. Then when you hit the release key, you could discard the errant card, and be on your merry way. Sorry about the mis-statement earlier.
 
  • Like
Likes jedishrfu
  • #59
I am reminded of a story at GE years ago where a top keypunch operator noted for her speed was brought into test the latest and greatest new keypunch machine guaranteed to handle the fastest typist until they met Sue. She typed so fast there were noticeable pauses on the machine while it struggled to keep up. She liked the machine but sadly no it’s wasn't fast enough for the best operators. The sales guy was quite flummoxed over it but GE bought a few anyway.
 
Last edited:
  • #60
Professor Knuth (Donald Knuth, of TAoCP and ##\TeX## fame) used to regularly outspeed the fastest electric typewriters. He loved the first IBM Selectric he encountered, in part because although he could outspeed it too, its buffering capability allowed it to catch up when he'd pause.
 
  • #61
The secret of the ASR 33 and ASR 35 teletype machines was some kind of force feedback (I don't know how it worked), that forced you to slow down and type in perfect rhythm with the machine. That did not make fast typing, but it greatly reduced the error rate.

Even today, I wager that I could type with fewer errors with the help of a metronome.
 
  • #62
Some vintage history on the teletype

http://www.samhallas.co.uk/repository/telegraph/teletype_story.pdf
And more specifically the asr33

https://en.m.wikipedia.org/wiki/Teletype_Model_33
The heavier key press was due to electromechanical feel of a typewriter. I suspect it may have been an engineering scheme to control the speed of the character bits written to tape or sent over the line as well as typing it on the paper. It’s true though you developed a certain rhythm when typing at about 10 characters per second.
 
Last edited:
  • Informative
Likes anorlunda
  • #63
anorlunda said:
The secret of the ASR 33 and ASR 35 teletype machines was some kind of force feedback (I don't know how it worked), that forced you to slow down and type in perfect rhythm with the machine.
A key part of that mechanism was the requirement for deep keystrokes. You had to push the key down about half an inch for it to register - and once one key was down, the next could not be pressed at all until the first key had fully returned to its original position. Since a key would not return to its original position until the cycle had ended, you couldn't type ahead at all.
 
  • Like
  • Informative
Likes jbriggs444 and anorlunda
  • #64
I've tried using Ctrl +C to break infinite loops, to no effect, in Jupyter notebooks . Do you know anything else that would break an infinite loop?
 
  • #65
WWGD said:
I've tried using Ctrl +C to break infinite loops, to no effect, in Jupyter notebooks . Do you know anything else that would break an infinite loop?

1671582850912.png

https://en.wikipedia.org/wiki/Power_symbol
 
  • Like
Likes DrJohn and WWGD
  • #66
WWGD said:
I've tried using Ctrl +C to break infinite loops, to no effect, in Jupyter notebooks . Do you know anything else that would break an infinite loop?
Kernel -> Interrupt, or the ■ button.
 
  • Like
Likes WWGD
  • #67
sysprog said:
You could wire the plug-board on a card duplicating machine to allow that, but how would you get, say, an IBM model 29 keypunch machine to do that? It not only doesn't detect which corner is cut, but also as far as I know, it has no capability to read anything on a card, except if you wrap the card around the program drum to be used as a program card, and in that case it could only heed the codes specific to that keypunch machine; not duplicate the card.
Since this thread has been bumped. I'll respond to this.
Here is a link to a 029 instructional video.
The actual mp4 file is here.
The photos below are from frames of that video.
This first image shows the part of the card bed between the punching station (out of frame to the right) and the read station (on the left).
029KeyPunchReadstationB.jpg

I have circled an important part of the card path. It is where a card can be manually fed to the read station.
There's a corresponding slot on the bottom of the card bed that is only barely visible from the cameras viewing angle.
To duplicate a damaged card, feed that damaged source card through that "slot" and feed a blank card to the punching station.
Then, hold down the "DUP" key:
029KeyPunchReadstationD.jpg

029KeyPunchReadstationE.jpg
 

Similar threads

Replies
5
Views
1K
Replies
10
Views
2K
Replies
9
Views
2K
Replies
43
Views
3K
Replies
17
Views
2K
Replies
16
Views
2K
Replies
31
Views
3K
Replies
2
Views
2K
Replies
3
Views
970
Back
Top