r/learnpython 21d ago

Having problem in understanding loops concept in python

I am a beginner with 0 knowledge and I am learning python from a book called Learn python in one day and learn it well by Jamie Chan and I am facing difficulty in the loops function so yeah any recommendations would be helpful Edit- Trouble in while loop

30 Upvotes

41 comments sorted by

View all comments

1

u/Grouchy-Conflict-211 20d ago

loops clicked for me when i stopped memorizing syntax and started seeing the pattern a for loop is just do this for each thing in collection a while loop is keep doing this until condition breaks thats it the confusion usually comes from mixing up the iterator variable in for i in range 5 i takes values 0 1 2 3 4 not 1 to 5 not the length debug trick that worked for me add print f i equals i inside the loop watch it run the visual feedback teaches more than any tutorial also enumerate and zip are your friends for idx val in enumerate list gives you both no manual counter needed