for loop iterates over first letter only
<p>My loop seems to iterate over the first letter and then breaks though it's supposed to iterate through each letter in the secretWord, for example, the code bellow is supposed to print out "_pp_e" but instead it only prints "_". I don't understand, what's the problem with that code??</p>

<pre><code>def getGuessedWord(secretWord, lettersGuessed):
    '''
    secretWord: string, the word the user is guessing
    lettersGuessed: list, what letters have been guessed so far
    returns: string, comprised of letters and underscores that represents
      what letters in secretWord have been guessed so far.
    '''
    # FILL IN YOUR CODE HERE...
    for letter in secretWord:
        if letter in lettersGuessed:
            return letter
        else:
            return '_'

print(getGuessedWord("apple",  ['e', 'i', 'k', 'p', 'r', 's']))
</code></pre>

<p>The return keyword exits the calling function. This should do the trick: </p>

<pre><code>def getGuessedWord(secretWord, lettersGuessed):

    result = ''
    for letter in secretWord:
        if letter in lettersGuessed:
            result += letter
        else:
            result += '_'
    return result

print(getGuessedWord("apple",  ['e', 'i', 'k', 'p', 'r', 's']))
</code></pre>

<p>Here, you start with an empty string as the result and either append a letter (if it was included in the list) or an underscore (if it was not), then return the result string.</p>

python debugging for-loop