Mysql While Loop Exit Python Coder