Search code examples
pythongoto

Goto statement in python - what other way is there?


My program has the following scturcutre

  1. program takes screenshot 2, program looks for condition a. if condition a is not met, it need to go back to point 1
  2. program looks for condition b. if condition b is not met, it need to go back to point 1
  3. program looks for condition c. if condition c is not met, it need to go back to point 1 ... etc

There are around 20 additional conditions and whenever one of them is not met, the program should return to the starting point. With a goto statement this could be easily solved. However, in Python this is not an option. Any suggestions are appreciated how this can be implemented elegantly.


Solution

  • You should give us the code, or at least an example showing what the structure really is.

    Maybe you could do so:

    take screenshot
    condition = (condition a) and (condition b) and ... and (condition z)
    
    while (not condition):
        take screenshot
        condition = (condition a) and (condition b) and ... and (condition z)