(This reminds that I wish ``iter`` could take a predicate instead of a sentinel as its second argument. Then you could just write for cmd in iter(get_command, lambda x: x.token == CMD_QUIT): cmd.do_something() )