Python syntax for an empty while loop

jsj picture jsj · Feb 10, 2013 · Viewed 42.4k times · Source

I have written this:

    while file.readline().startswith("#"):
        continue

But I suspect the continue is unnecessary? What is the correct syntax for what i'm trying to achieve?

Answer

ogzd picture ogzd · Feb 10, 2013
while file.readline().startswith("#"):
    pass

This uses the pass statement :

The pass statement does nothing. It can be used when a statement is required syntactically but the program requires no action.

http://www.network-theory.co.uk/docs/pytut/passStatements.html