I have a long, I2C python program for a I2C MUX Board that I am making. I have 4 MUXs, in my program I am using a while loop for each one. Within the while loops, I have this structure (to make it easier to read I won’t put all of the code unless requested:
while True:
action = input ('...')
if action == '0':
try:
action = input("...")
if action == 'w':
...
elif action == 'r':
...
except ValueError:
print("Invalid input, pick again")
pass
I want the while loop to continue until the user selects something like ‘c’ instead of a number between 0 and 7 (there are 7 more elif statements for numbers 1-7). If they don’t hit c then I want that while loop to continue. If they do hit c, I want the code to go to the next while loop for the next MUX. Any suggestions?
To sum it up, what’s the best way to end multiple loops at once to go to the next part of the code?
Currenlty, after the other 7 elif statements, I have an elif statement in that while loop that says:
#If user selects 'c' to exit MUX 1 and go on to MUX 2
elif action == 'c':
break
Is there a better way to do it? Or is this the best way/will this way work?
Beau Raley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3