An endless loop
Steve D'Aprano
steve+python at pearwood.info
Sun Oct 15 01:37:54 EDT 2017
On Sun, 15 Oct 2017 01:43 pm, Dennis Lee Bieber wrote:
> On 15 Oct 2017 02:10:15 GMT, ram at zedat.fu-berlin.de (Stefan Ram) declaimed
> the following:
[...]
>>def poly( n, length ):
>> i = 0
>> while i < n:
>> forward( length )
>> left( 360/n )
>>
>
> A clear example of why a pre-determined loop is better using "for" then
> emulated with a non-deterministic "while".
>
> for i in range(n):
>
> avoids having to write separate initialization, test, and increment
> statements.
This, a thousand times this.
I'm reminded of an old joke:
A mathematician, a physicist, an engineer and a computer programmer are
discussing prime numbers and whether or not every odd number is prime.
The mathematician says "3 is prime, 5 is prime, 7 is prime. So by induction,
all odd numbers must be prime."
The physicist says "3 is prime, 5 is prime, 7 is prime, 9 is an experimental
error, 11 is prime, 13 is prime... within 83% confidence limits, all odd
numbers are prime."
The engineer says "3 is prime, 5 is prime, 7 is prime, for safety we better
treat 9 as prime, 11 is prime..."
The computer programmer says "Listen you guys, you're all doing it wrong. I've
written a program to check for primes, it says: 1 is prime, 1 is prime, 1 is
prime, 1 is prime ..."
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list