3 ms·
On the contrary: the loop isn’t fundamentally infinite, it’s just an artefact of the language that you have to write it that way. The walrus lets you put the te
by pdpi 7y ago
On the contrary: the loop isn’t fundamentally infinite, it’s just an artefact of the language that you have to write it that way. The walrus lets you put the termination where it belongs.
- pyrale 7y agoI don't understand that the walrus has any significance with regards to the `while` loop termination. it's the nature of the evaluated expression that makes a difference, more precisely, whether it will return something that is cast to False. In that sense, while loops over expressions always require knowledge of the expression to understand the semantic. On the other hand, something like: while True: with x as y: print(y) would not require understanding of x to understand the intent. Therefore it is not semantically equivalent to: while x as y: print(y) Note that in both cases, `:=` is strictly equivalent to `as` as it is defined for `with`. That is a matter of personal preference.