On Mon, Dec 1, 2008 at 6:44 PM, WM. <[EMAIL PROTECTED]> wrote: > I recently asked a question about 'for' loops, expecting them to be similar > to 'for-next' loops. I have looked at several on-line tutors but am still > in the dark about what 'for' loops do. > Does anyone have a plain English about the use of 'for' loops? > Are 'while' loops the only way Python runs a sub-routine over & over?
For loops are mainly used when you want a specific number of iterations, such as looping over the elements of a list. In C/C++ you would do something like this: int myarray[] = {1, 2, 3, 4, 5}; for(int x = 0; x < 5; x++) printf("%d", myarray[x]) In python it would be much cleaner: myarray = [1, 2, 3, 4, 5] for x in myarray: print x HTH, Wayne -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor