Ask coding questions

← Back to all posts
Loops in python are super confusing am I right or wrong? PYTHON
YvngBashit (15)

So can some one please explain for and while , I know that in while loops if you get True it executes the program if its false it does not. But what about For loops? The things you put down under a while loop are also quite confusing? May some one please explain?

Commentshotnewtop
AlephZero (339)

For loops in Python can indeed be confusing, especially if you come from a different language.

I think a good source to learn from is the Python documentation:

For loops:
https://docs.python.org/3/tutorial/controlflow.html#for-statements
https://docs.python.org/3/tutorial/controlflow.html#the-range-function

While loops:
https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming

For more information, you can check out the Python wiki:
https://wiki.python.org/moin/ForLoop, https://wiki.python.org/moin/WhileLoop

JoshDaBosh (79)

you iterate through a certain number of times (the most simple for loop)

basically you run the code inside the for loop for the amount specified.

also im not trying to be rude or anything but you're pretty wrong about them being confusing in python, if you've seen loops in other languages

AlephZero (339)

@JoshDaBosh I disagree, for loops in Python aren't similar to traditional for loops (for example in Java or C). They resemble for-each loops more than anything.

YvngBashit (15)

@JoshDaBosh Thank you for your help python my first language I am learning