title: Why statements after the while loop are not always executed?
body: <p>I am very new to python and I have encountered the following code:</p>
  
  <pre><code>def function(array):
      i = 0
      j = 10
      while i &lt; j:
          if array[i]!=array[j]
              return False
          i += 1
          j -= 1
      return True
  </code></pre>
  
  <p>I can't understand why the <code>True</code> value is not always assigned to the function no matter what happens in a <code>while</code> loop. The <code>while</code> loop just seems to check the <code>if</code> statement, and after finishing the loop, the <code>True</code> value should be assigned to the function anyway. But this code works as follows: the <code>if</code> statement checks for the condition and if it is true, we assign <code>False</code> to the function, if it is not true, we assign <code>True</code> to the function. But the assignment of <code>True</code> is not inside the while loop, so we should have assigned the <code>True</code> to function anyway, no matter what happens in <code>while</code> loop. I can't understand the logic here, can anyone enlighten me in this. Thanks a lot.</p>