MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/PythonLearning/comments/1x5t0ra/while_loop/pgpdbsj/?context=3
r/PythonLearning • u/Monesh_peterson1025 • Oct 14 '26
can anybody explain the concept of while loop
38 comments sorted by
View all comments
1
While loop repeat the code inside until a certain condition is met, you use it when you don't know how many times you want to run the loop.
For loop, for comparison, repeats the loop a set amount of time. Albeit nothing prevents you from doing the same with while loop, but don't do that.
1 u/oclafloptson Oct 14 '26 For loops loop through an iterable. This might be a range, a list, or even each character in a string. With mutable objects like lists you might not actually know how many iterations there will be
For loops loop through an iterable. This might be a range, a list, or even each character in a string. With mutable objects like lists you might not actually know how many iterations there will be
1
u/Why_so_loud Oct 14 '26
While loop repeat the code inside until a certain condition is met, you use it when you don't know how many times you want to run the loop.
For loop, for comparison, repeats the loop a set amount of time. Albeit nothing prevents you from doing the same with while loop, but don't do that.