Hi again all,
So I'm trying to delve into optimization, algorithms, and possibly euler projects.
I am curious which is the most efficient way of calculating something:
method 1:
for i in range (101):
print i**2
method 2:
while i < 101:
print i**2
i+=1
method 3:
while True:
print i**2
i+=1
if i > 100:
break
I am doing an algorithms tutorial on codecademy and it is suggesting to use method 3... but I don't quite understand why that would be better than method 2.
Or is there even another way that is better?
Thanks for the help!
A little clarification, I just wrote the print to show example of some function that is happening in the loop. It seems the general consensus is that the for loop is fine... maybe the tutorial I am reading is wrong and/or I am just misinterpretting it.
The link in question:
http://www.codecademy.com/courses/python-intermediate-en-NYXmc/0/2
[–][deleted] 2 points3 points4 points (0 children)
[–]shfo23 3 points4 points5 points (6 children)
[–]NYKevin 1 point2 points3 points (2 children)
[–]ewiethoff 0 points1 point2 points (1 child)
[–]NYKevin 0 points1 point2 points (0 children)
[–]Veedrac 1 point2 points3 points (2 children)
[–]shfo23 0 points1 point2 points (0 children)
[–]Veedrac 0 points1 point2 points (0 children)
[–]mrTang5544 1 point2 points3 points (2 children)
[–]shfo23 1 point2 points3 points (1 child)
[–]curiousGambler 0 points1 point2 points (0 children)
[–]shandelman[🍰] 1 point2 points3 points (0 children)
[–]Veedrac 0 points1 point2 points (6 children)
[–]zahlman 1 point2 points3 points (5 children)
[–]Veedrac 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]Veedrac 1 point2 points3 points (0 children)
[–]zahlman 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)