--Originally published at codemathblog.wordpress.com
For read this post you need to know about loops (for and while functions) so you can understand better when to use each one.
Here we have an example of a for loop:
And here we have a while loop:
In a for loop you kind of know how many times your loop will repeat, you have the number! meanwhile in a while loop you don’t know how many times it will repeat because it will be running until the condition is not true.
As simple as that! for=n times whilee= no idea how many times
Hope it was useful! I will let you some links where you can look for more information:
http://stackoverflow.com/questions/920645/when-to-use-while-or-the-for-in-python