[Tutor] Beginners question

Mats Wichmann mats at wichmann.us
Wed Apr 1 19:10:42 EDT 2020


On 4/1/20 4:48 PM, DL Neil via Tutor wrote:
> On 2/04/20 3:05 AM, Mats Wichmann wrote:

ah, too much to reply to there, David :)

>> On 3/31/20 4:37 PM, DL Neil via Tutor wrote:
>>> Earlier, I opined that the first code-snippet is "untidy".
>> curious: why?

> The 'book of words' says: <<<"while" assignment_expression ":" suite>>>.
> Which most of us will understand as: "while condition: do-something".
> 
> In the proposed-code/answer, this construct is used/abused, by removing
> the condition, ie to say: "loop forever".
> 
> As such, it is necessary to add a second structure, an "if-it's-the-end"
> or a "raise exception", in order to realise some condition under which
> the while-loop should terminate.

well, it's a restatement, not really a fundamental change. You can write
it thus:

get something
while something != exitvalue:
   do summat with something
   get something

or thus like the example you're grumping at:

while condition-that-always succeeds:
  get something
  if something == exitvalue:
      break
  do summat with something

I guess pick the one you like better? (some seem to find the initial
fetch/set before starting the loop obnoxious, I don't really care).


> Accordingly, I stick with the recommended
> 79?80-characters per line - and yes, I can spell "Hollerith punched
> card", even bemoan their passing and that of the IBM 029 Card Punch
> machine (but not the LOUD noise it made). Reject cards made excellent
> book-marks - but wait, who uses paper-books these days...?

*I* don't miss unjamming cards... one with maybe a fractionally bent
spot on the edge would catch, and then the next six or so cards in
flight behind it would smash in behind it and make an unholy mess...
but you reminided me:  those punchcards were also "indentation matters",
just like Python :)  (Fortran II - statements had to begin in column 7,
because the first six columns were reserved, including for line numbers
for, yes, something to GOTO.

However... it's time to forget those days.




More information about the Tutor mailing list