0

I've managed to iron out the bugs previous to this one showing up and I've copied the code exactly as is stated in the chapter but I am getting this error being thrown up and I can't seem to fix it:

File "xkcd.py", line 34
continue
^
SyntaxError: 'continue' not properly in loop.

Here is my code:

comicElem = soup.select('#comic img')  
if comicElem == []:
    print('could not find comic image.')
else:
    try:
        comicUrl = 'http:' + comicElem[0].get('src')
        # Download the image.
        print('Downloading image %s...' % (comicUrl))
        res = requests.get(comicUrl)
        res.raise_for_status()
    except requests.exceptions.MissingSchema:
        # skip this comic
        prevLink = soup.select('a[rel="prev"]')[0]
        url = 'http://xkcd.com' + prevLink.get('href')
        continue

I understand the obvious, because of the error being perfectly clear but as a newbie copying code straight from the site and not coming across this sort of thing previously, I am struggling to understand where the issue really is.

Varg
  • 1
  • 1
  • There is no loop. `continue` advances to the next iteration. – Malik Brahimi Jan 17 '16 at 14:55
  • What you you expect the `continue` to do where you've placed it? – mfitzp Jan 17 '16 at 15:01
  • I haven't placed it there as something I have personally written. This has come from the website "automate the boring stuff with python" and this is copied exactly as it is written on the site. – Varg Jan 18 '16 at 05:03
  • Does this answer your question? [syntaxError: 'continue' not properly in loop](https://stackoverflow.com/questions/14312869/syntaxerror-continue-not-properly-in-loop) – Sören Jun 11 '22 at 09:45

1 Answers1

0

continue should be used inside of a loop (for, while). There is no loop in your code.

mattsap
  • 3,790
  • 1
  • 15
  • 36