Https://www.codecademy.com/courses/learn-python-3/lessons/introduction-to-strings/exercises/strings-in-conditionals-i?action=resume_content_item

How does this code work when the next letter can return False
Strawberry has a and this returns True
but its a for loop and checks next one also.
if it checks w it should return False from then…

def letter_check(word, letter):
for character in word:
if character == letter:
return True
return False

1 Like

no, the for loop can’t do that. Once a return keyword is reached, the function will stop. It handed back a result, so its job is done. Just like when you hand in an assignment, once you hand the assignment in, you are not continue working on the assignment.

1 Like

so at the beginning itself it has to return False. S is false and should’nt continue

1 Like

no, false is nested outside/after the loop, so the loop first has to run. Maybe run your code here:

http://www.pythontutor.com/visualize.html#mode=edit

so you can visualize the steps.

1 Like

Thanks That Helped me :slight_smile:

1 Like