pythoncwhile-loop

Python "While not" loop in C


I have written a function in Python that uses a while loop with an inverted condition like this:

while (not x < 0):
 #do something

Is there an elegant solution to map this over to C without having to change the function logic etc?


Solution

  • Assuming x can only be a number in the Python code, the following would be equivalent:

    while ( ! ( x < 0 ) ) STMT
    

    Of course, it would be far more readable if written as follows:

    while ( x >= 0 ) STMT