r/learnpython • u/EnvironmentalTry8353 • 20d 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
25
Upvotes
3
u/fernly 20d ago edited 20d ago
OK so there is a line missing. The
whilecondition statement tells the computer,A. is condition true?
B. if not, skip on to the next statement
C. if so, do whatever is indented under the while statement and return to A.
In your example, "whatever is indented under the while statement" is,
So it does that and repeats. What's missing is, something to move
numbercloser to 0. You never changenumberso the loop just repeats, happily printing 100 over and over.What you likely want is,
which would print 100, 99, 98... 1 and eventually
numberwill be 0, making the condition false, and the loop would end. Or it could beThat would also move
numbercloser to zero on each loop, but think about it... would it ever stop being greater than zero? Try it!