[Tutor] for loop
Alan Gauld
alan.gauld at btinternet.com
Wed Jun 11 05:33:31 CEST 2008
"Sean Novak" <snovak at snovak.com> wrote
> I would normally write this in PHP like this:
>
> for($i=1; i< count($someArray); $i++)
> {
> print $someArray[i]
> }
>
> essentially,, I want to loop through an array skipping
> "someArray[0]"
for i,n in enumerate(myArray):
if i == 0: continue
print n
is how I'd do it.
> but in python the for syntax is more like foreach in PHP..
Indeed it is exactly like a foreach. I wish it were called foreach
except that its more typing. But it would save much confusion
among newbies!
> count = 0
> for i in range(1,10):
> if count == 0:
count += 1
> continue
> else:
> print i
Should work
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list