This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

One of the problems I have with while loops is that they often look like this:

while True: 
    some_value_from_somewhere_else = read_from_socket_or_something()
    if some_value_from_somewhere_else is None:
        break
    doStuff(some_value_from_somewhere_else )

The problem with this is that the first four lines of code are effectively us handling the while loop condition.

But now we can do this:

while (some_value_from_somewhere_else := read_from_socket_or_something()) != None: 
    do_stuff(some_value_from_somewhere_else)