title: Python: Nested loop not reached
body: <p>I have a table that looks like this:</p>
  
  <pre><code>table = [[0, 11, 12],
           [21, 'a', 'b'],
           [22, 'c', 'd']]
  </code></pre>
  
  <p>My program should get an input such as 2211 and find the row based on the first two numbers (22) and the column based on the next two numbers (11), and get the element in the intersection of the row and column. In this case it would output 'c'. Another example would be input: 21112212 and output: 'a' 'd'.</p>
  
  <p>I tried to do this:</p>
  
  <pre><code>code = str(raw_input('Input code: '))
  </code></pre>
  
  <p>I assumed the input would be in the correct format (string of numbers, length divisible by 4)</p>
  
  <pre><code>result = ''
  n = 0
  </code></pre>
  
  <p>I used n because the user could want to get more than one element from the table.</p>
  
  <pre><code>for a in range(1, len(code)/4 + 1):
  </code></pre>
  
  <p>Loops for each set of four numbers.</p>
  
  <pre><code>    x = 0
      y = 0
      for i in range(1, 3):
          if table[i][0] == code[(0+n):(2+n)]:
              x = i
  </code></pre>
  
  <p>This checks if the first two numbers (22 for example) exist in the table. If they do I set x to be i. I tried putting print table[i][0] here to see if this was the problem, and it does not print anything, but I don't know why.</p>
  
  <pre><code>    for j in range(1, 3):
          if table[0][j] == code[(2+n):(4+n)]:
              y = j
  </code></pre>
  
  <p>Does the same as the previous section, just for the column.</p>
  
  <pre><code>    n += 4
  </code></pre>
  
  <p>Increment n by 4 to get the next element, if there is one.</p>
  
  <pre><code>    if x != 0 and y != 0:
          result += table[x][y] + ' '
      else:
          print 'Not in table'
  
  print result
  </code></pre>
  
  <p>So if it found 22 and 11 in the table it would take the row number from the first and the column number from the second and add the according element to the result. </p>
  
  <p>So for the input 2211 instead of printing 'c' it prints 'Not in table' when it actually is.</p>