title: What is the right place to put "return"?
body: <p>I am a new bird following udacity to learn some python. Got really confused about where to put the return to end a loop. I understand that the code provided in the answer will work. But I don't understand why my own code wouldn't. 
  I would really appreciate some help! Thank you very much!</p>
  
  <p>The quiz is:
  Define a procedure, add_to_index,
  that takes 3 inputs:</p>
  
  <ul>
  <li>an index: [[,[,...]],...]</li>
  <li>a keyword: String</li>
  <li><p>a url: String</p>
  
  <p>If the keyword is already
  in the index, add the url
  to the list of urls associated
  with that keyword.</p>
  
  <p>If the keyword is not in the index,
  add an entry to the index: [keyword,[url]]</p></li>
  </ul>
  
  <p>my code is:</p>
  
  <pre><code>index = []
  def add_to_index(index,keyword,url):
      for element in index:
          if element[0] == keyword:
              element[1].append(url)
          else:
              index.append([keyword,[url]])
          return index
  </code></pre>
  
  <p>and the answer given is:</p>
  
  <pre><code>index = []
  def add_to_index(index,keyword,url):
      for element in index:
          if element[0] == keyword:
              element[1].append(url)
              return
      index.append([keyword,[url]])
  </code></pre>
  
  <p>why does the index.append([keyword,[url]]) have to be out of the loop? I thought after each element in the index was went through, the loop will terminate itself. Is it true?</p>