Need help understanding this while loop
Python While Loop Syntax - Stack Overflow
[python] For loops vs while loops
Why would somebody use a loop construct when there is goto? Why would somebody use a high-level language when there is assembly language? Why would somebody name their variables when they can just use the memory addresses?
Answer: Because writing code that intuitively "looks like" the thing it is intended to do, both a) makes writing programs much less work, b) dramatically reduces the number of bugs, and c) greatly decreases the difficulty of reading, understanding, and maintaining the code later.
We use for loops when we want to loop over a range, or loop over the elements of a set. This is a fixed operation over a known amount of steps. Essentially, we are saying something along the lines of "for each employee, calculate the salary and submit a payment", so we call it "for" to highlight this relationship. In the case of Python, for loops also provide a special efficient syntax for looping over the elements of a set, so it's less work to type the thing in too. Some other languages call that variant of the for statement "foreach".
We use while loops when we want to continue repeating an operation while a condition continues to hold. For example, we continue looping as long as we encounter no errors, or as long as we receive more data from a network connection. These are not fixed ranges, but take place while a condition holds, so we call it "while".
More on reddit.comWhats the difference between a while loop and a for loop?
Videos
The while current: syntax literally means while bool(current) == True:. The value will be converted to bool first and than compared to True. In python everyting converted to bool is True unless it's None, False, zero or an empty collection.
See the truth value testing section for reference.
Your loop can be considered as
while current is not None:
because the parser will try to interpret current as a boolean (and None, empty list/tuple/dict/string and 0 evaluate to False)