On 24/11/13 22:38, Alan Gauld wrote: Responding to my own post, never a good sign :-(
primes = [] for n in range(1000) if n%2 == 0: even numbers aren't prime continue else: if isPrime(n): primes.append(n) Now the continue means the isPrime test never gets executed, saving a lot of processing. Without continue you would need to execute the test and the only way to save the time would be to move the n%2 test inside the isPrime() function
As soon as I posted it I realized that wasn't true, you could do this instead... for n in range(1000): if n%2 == 1: if isPrime(n): primes.append(n) So a bad example, sorry. DeMorgan wins again. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor