I’m not new to python as a whole but I’m very bad at it however, I want to learn. I’ve tried to do some coding but I want to know what everything is actually doing rather than just reciting things online so if some of you could explain it to me as if I was like a baby that would make me really happy.
I would say an LLM tool may be more helpful in this case, just for the reactivity of the response and for an experience more tailored to your needs.
That said, a while loop is concept related to control flow, they’re not a python exclusive feature and basically any programming language uses it in some form. I would say start with the wikipedia article about it to get some familiarity.
While Loops, how do they work?
while condition:
code
Run the code again and again while the condition is True.
For example:
cookies = 5
while cookies > 0: # condition is cookies > 0
print("Eating a cookie")
cookies -= 1
You also have the notion of infinite loop:
while True:
print("ok")
You would need to have a condition in the body of the loop for it to brake out of it.
Or use a break statement.
while True:
print("ok")
break
This prints “ok” just once. Usually, break follows an ‘if’ condition.