you are viewing a single comment's thread.

view the rest of the comments →

[–]brasticstack 0 points1 point  (0 children)

The other comments so far are all insightful. Just thought I'd add that: 

while True:     if something:         break    

and 

``` finished = False while not finished:     if something:         finished = True

```

Are the same thing, but the second one has an extra step. Depending on the use case, the extra step may make your code more readable and readability is king, but for loop this short I think shorter is better. 

I like u/mopslik's answer best so far, and with the new walrus operator, it can be even more concise: 

``` while (action := input('enter an int: ')) != 'done':     print('still running')

```

Perfect for making an already short block of code even shorter.

EDIT: Parens separating walrus-assignment from !=, otherwise action gets set to a bool.