On 11/04/20 10:20 am, haael wrote:

     class InvariantError(AssertionError):
         pass

     def loop_invariant(condition:bool):
         if not condition:
             raise InvariantError
         return True

     for element in iterable if loop_invariant(condition):
         loop_body

That's a *very* misleading way to check loop invariants,
because it makes it look like a filter rather than an
invariant check.

Also it doesn't quite do a complete job, because it
doesn't check the invariant after the last iteration,
and doesn't check it at all if the iterable is empty.

     while loop_invariant(condition) and running:
         loop_body

Again misleading, because it looks like part of the
loop condition.

--
Greg
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/WSCGRVGNIJEV4AXY2SJXPD6MZRLASXWG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to