r/learnpython • • Jul 31 '22

Loops in python are weird

I recently started learning python programming. I also had some exposure to programming in my high school.

Today I studied loops but I found them a little bit weird...they do not have any initialisation, condition and increment like other languages like javascript.

It is very confusing to me PLEASE HELP!!

0 Upvotes

7 comments sorted by

View all comments

7

u/shiftybyte Jul 31 '22

Python's for loop are equivalent to javascript's foreach loops.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

Python also has while loops for a more classical init/condition/increment approach.

8

u/skyboyer007 Jul 31 '22 edited Jul 31 '22

...or rather for .. of .. in JS

but with optional access to index(if using enumerate())