title: Getting an IndexError: string index out of range
body: <p>I'm not sure why I'm getting an </p>
  
  <blockquote>
    <p>IndexError: string index out of range </p>
  </blockquote>
  
  <p>with this code. </p>
  
  <pre><code>s = 'oobbobobo'
  a = 0
  for b in range(len(s)-1):
      if (s[b] == 'b') and (s[b+1] == 'o') and (s[b+2] == s[b]):
          a += 1
      elif (s[b] == 'b') and (s[b+1] == 'o') and None:
          break 
  
  print("Number of times bob occurs is: ", a)
  </code></pre>
  
  <p>I thought the <code>elif</code> statement would fix the error, so I'm lost.</p>