Using Continue Statment in nested for loop in Python
===

Hi I have a function that read in data from two files.  What I want to be happening is that the outer loop starts to read in the the first file and if lum from the first file is greater than the defined value (LC) the loop skips to the next iteration. If not the code moves to the
inner loop which reads in the hlist and builds the x,y,z lists if idc and id are the same. If  idc and id are not the same value it skips to the next iteration of the inner loop. When I print test statments I am getting the same values over and over again. It seems as if the inner loop is not iterating and its not clear to me why. I would appreciate any help

Code

    def read_file(F):      #Function that reads data froma file  
                       #and extracts specific data columns
     X = []
     Y = []                # Creats Data Lists
     Z = []
     Idh = []
     Id = []
     LC = float(sys.argv[1]) #LMagnitude of Luminosity cuttoff 
     N = 11#912639            # number of lines to be read
     Nl = 11#896030
     fl = open(Fl)            #opens catalog file
     fl.readline()
     nlinesl = islice(fl,Nl)
     f = open(F)           #Opens hlist file
     f.readline()          # Strips Header
     nlines = islice(f, N) #slices file to only read N lines
             
     for linel in nlinesl:             
        if linel !='':
          linel = linel.strip()               #Loop Strips empty lines as well as replaces tabs with space
          linel = linel.replace('\t','')
          columnsl = linel.split()
          lum = float(columnsl[1])
          idc = int(columnsl[0])
          if lum >= LC:
            continue
          print("lum1 =",lum)
          #Id.append(idc)
          print("Id=",idc)
         for line in nlines:
            if line !='':
            line = line.strip()
            line = line.replace('\t',' ')
            columns = line.split()
            id = int(columns[1])
            #Idh.append(id)
            if id !=  idc:
                continue
            print('idc =',idc,'id =',id)
            x = columns[17]             # assigns variable to columns
            y = columns[18]
            z = columns[19]
            X.append(x)
            Y.append(y)                #appends data in list
            Z.append(z)
            

     print(X)     
     X = [ float(p) for p in X ]        #Converts lists to NumPy arrays
     Y = [ float(p) for p in Y ] 
     Z = [ float(p) for p in Z ]
     Xa = numpy.array(X, dtype=float)
     del X[:]
     Ya = numpy.array(Y, dtype=float)
     del Y[:]
     Za = numpy.array(Z, dtype=float)
     del Z[:]


 return(Xa,Ya,Za)       
        


The format of the catalog file is 

    column[0] columns[1]
    id's           lum's






 Print out. As you can see the value in the X list does not change and the list is not getting appended. The values of lum are changing , but idc and id are not changing in the inner loop. 


    khary@khary-VirtualBox:~$ python /home/khary/Astrophysics/Count_FixedLoop.py -21.5 125
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ( 'idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
    ('lum1 =', -21.78545)
    ('idc=', 2701276876L)
    ('idc =', 2701276876L, 'id =', 2701276876L)
    ('lum1 =', -21.69835)
    ('idc=', 2699751347L)
    ('lum1 =', -21.69942)
    ('idc=', 2699724518L)
    ('lum1 =', -21.74543)
    ('idc=', 2699724331L)
    ('lum1 =', -21.60912)
    ('idc=', 2699724726L)
    ('lum1 =', -21.53862)
    ('idc=', 2699725014L)
    ('lum1 =', -21.53155)
    ('idc=', 2701277269L)
    ['34.57223']
 
    
