title: Why my logic is not working for Binary search program?
body: <p>I'm trying to create my <code>Binary Search</code> program using Python. But every time i get stuck with <code>while loop</code>. It looks i need to put <code>break</code> for every condition. But it'd would create a mess for my whole logic.</p>
  
  <p>Kindly help me, How to get rid of such situations:</p>
  
  <pre><code>print("Enter your number of elements:")
  num = int(input())
  
  array = []
  
  print("Enter your %d elements" %num)
  for c in range(0, num):
      arrayNum = int(input())
  
      #Use "append" concept under array into python.
      array.append(arrayNum)
  
  print("Enter a value which you want to find: ")
  search = int(input())
  
  first = int(0)
  
  last = int(num-1)
  
  middle = int((first + last)/2)
  
  while first &lt;= last:
      if array[middle] &lt; search:
          first = int(middle+1)
  
      elif array[middle] == search:
          break
          print("%d is found at location" % search, (middle+1))
  
      else:
          last = int(middle-1)
          middle = int((first+last)/2)
  
  if first &gt; last:
      print("%d is not present in list"%search)
  </code></pre>
  
  <p>When i run my program, It looks <code>while loop</code> is still running. Please help me.</p>
  
  <p>HELP WOULD BE APPRECIATED!</p>