close

[Solved] syntaxError: ‘continue’ not properly in loop

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error syntaxError: ‘continue’ not properly in loop in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How syntaxError: ‘continue’ not properly in loop Error Occurs?

Today I get the following error syntaxError: ‘continue’ not properly in loop in python.

How To Solve syntaxError: ‘continue’ not properly in loop Error ?

  1. How To Solve syntaxError: 'continue' not properly in loop Error ?

    To Solve syntaxError: 'continue' not properly in loop Error continue is only allowed within a for or while loop. You can easily restructure your function to loop until a valid request.

  2. syntaxError: 'continue' not properly in loop

    To Solve syntaxError: 'continue' not properly in loop Error continue is only allowed within a for or while loop. You can easily restructure your function to loop until a valid request.

Solution 1

continue is only allowed within a for or while loop. You can easily restructure your function to loop until a valid request.

def writeHandlesToFile():
    while True:
        with open("dataFile.txt","w") as f:
            try:
                lst = tweepy.Cursor(tweepy.api.followers,screen_name='someHandle',).items(100000)
                print "cursor executed"
                for item in lst:
                    f.write(item.screen_name+"\n")
                break
            except tweepy.error.TweepError as e:
                print "In the except method"
                print e
                time.sleep(3600)

Solution 2

The problem might be in the way you are using continue

continue may only occur syntactically nested in a for or while loop, but not nested in a function or class definition or finally statement within that loop.6.1It continues with the next cycle of the nearest enclosing loop.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read