-2

I have python 2.7, this is my code and when I run it, I get this error: 'continue' not properly in loop.

I know that 'continue' should be inside the loop for, but I use it inside if, then what i have to do?

from numpy import zeros
from scipy.linalg import svd
from math import log
from numpy import asarray, sum
#from nltk.corpus import stopwords
from sklearn.metrics.pairwise import cosine_similarity
#from nltk.stem import PorterStemmer
#from nltk.stem.isri import ISRIStemmer
import nltk
#from matplotlib import pyplot as plt
from snowballstemmer import stemmer 


titles = [" ذهبت الاخت الى المدرسة","تقع المدرسة في الجبال",
    "ذهب الام لزيارة ابنتها في المدرسة ","تحضر الام الكعكة" ]

ar_stemmer = stemmer("arabic")

stopwords = ['ثم','و','حتى','الى','على','في']

ignorechars = ''',:'!'''



 class LSA(object):
  def __init__(self, stopwords, ignorechars):
    self.stopwords = stopwords
    self.ignorechars = ignorechars
    self.wdict = {}
    self.dcount = 0    


def parse(self, doc):
    #tokens=nltk.word_tokenise(titles)
    #words = doc.split();
    #ar_stemmer = stemmer("arabic")
    for word in titles.split(" "):
      #  w = w.lower()

    #for w in titles.split(" "):
              stem = ar_stemmer.stemWord(word)

        #st = ISRIStemmer()
    #for w in words : 
            #join = w.decode('Windows-1256')
           # w= st.stem(w.decode('utf-8'))

    if stem in self.stopwords:
       continue
    elif stem in self.wdict:
            self.wdict[stem].append(self.dcount)
    else:
            self.wdict[stem] = [self.dcount]
            self.dcount += 1
Assem
  • 11,574
  • 5
  • 59
  • 97
YayaYaya
  • 125
  • 2
  • 3
  • 10
  • 1
    Your indentation is seriously messed up. Indent your code consistently to resolve the error. – user2357112 May 31 '16 at 21:58
  • Going off of above, your if statement is not actually in for loop, indent one more to be part of it. – chrishorton May 31 '16 at 22:01
  • As written, your `parse` function only processes the last value of `stem`. Is that intentional? If not, indent the `if` statement to the same level as `stem = ar_stemmer.stemWord(word)`. –  May 31 '16 at 22:27

2 Answers2

2

It's totally unnecessary to use continue in that context, just use pass.

mcchucklezz
  • 376
  • 1
  • 16
2

This error is caused by using continue outside of for or while loop. That is to say: continue is only allowed within a for or while loop.

Umar Yusuf
  • 926
  • 2
  • 13
  • 30