3 ms·
The last version clearly exposes that you have an infinite loop. This is something hidden by the `while(evaluate)` expression. Also if it comes to pure form I
by pyrale 7y ago
The last version clearly exposes that you have an infinite loop. This is something hidden by the `while(evaluate)` expression.
Also if it comes to pure form I would have preferred `while (evaluate) as x:` out of establishing a parallel with existing syntax, but that's not very important.
- pdpi 7y agoOn 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.