A similar feature is found in Common Lisp's LOOP macro, described here by Peter Seibel:
...LOOP provides two keywords, initially and finally, that introduce code to be run outside the loop's main body.
After the initially or finally, these clauses consist of all the Lisp forms up to the start of the next loop clause or the end of the loop. All the initially forms are combined into a single prologue, which runs once, immediately after all the local loop variables are initialized and before the body of the loop. The finally forms are similarly combined into a epilogue to be run after the last iteration of the loop body. Both the prologue and epilogue code can refer to local loop variables.
The prologue is always run, even if the loop body iterates zero times. The loop can return without running the epilogue if any of the following happens:
- A return clause executes.
- RETURN , RETURN-FROM, or another transfer of control construct is called from within a Lisp form within the body...
For example, part of a Python sample found in the linked question:
for v in known_variables:
if self.bindings[v] is cell:
return v
else:
raise CannotSimplify
might look something like this:
(loop for v in known-variables
when (eq (gethash v (slot-value self bindings)) cell)
do (return v)
finally (signal cannot-simplify))
Another observation:
Common Lisp's condition system is also unique. Someone, once, asked where it came from and was pointed to Kent Pitman's paper, where he says got it from Maclisp. Similarly, Common Lisp's weird-looking FORMAT function apparently came from Multics via Dan Weinreb.
The common thread is that language features don't tend to follow from the ancestor language that most inspired this language, but are taken by individuals who loved them to whatever new language they're working on. So if you want to find out the actual source of Python's for
-else
, I'd look for who added it, and see what language they worked on prior to that.