Reading a controll character in a loop in Python I have a code snippet below and because of habit from other programming languages I wanted to use a do-while loop instead. But Python offers only the construct which I show as a second code snippet instead of a do-while*loop.
What is the best pythonic way to code this?

ch = getch()
while ch != "q":
  do_something()
  ch = getch()


while True:
  ch = getch()
  do_something()
  if ch == "q":
    break
Another way would be using a generator expression. This has the effect of separating the 'control logic' and the 'action logic' (and are extremely useful!).

def getchar_until_quit():
    while True:
        ch = getch()
        if ch != "q": 
            yield ch
        else:
            raise StopIteration

for ch in getchar_until_quit():
    do_something()
do_something() # to process the 'q' at the end