I can't understand Py43 database example

Hi! I am doing my first python course with Dr.chuck and it has been really interesting and joyful to learn new language. However, while I am following exercises I couldn’t understand this following example code .

The full version of code is in this link. I am not sure I can share whole code with copy and paste so I leave this link here.
The part I don’t get is

def lookup(d, key):
    found = False
    for child in d:
        if found : return child.text
        if child.tag == 'key' and child.text == key :
            found = True
    return None

This function. I don’t know why

if found : return child.text

is ahead of

if child.tag =='key' and child.text == key :

I’ve read a comment below of this youtube video, however I still didn’t get it. Maybe my English is not good enough to follow but I wonder if there’s anyone can help me to understand . Thank you in advance and If there’s any problem with this post for sharing code and materials , please let me know so I can fix this post or delete it.

So what happens,
when you test all cases:

  1. his code + child was found
  2. his code + child was not found
  3. your code + child was found
  4. your code + child was not found

Do you see some differences?

1 Like

Hi ! Thank you for the reply. Is because found return to true then it runs function continuously? I don’t feel I understand 100% .

Doesn’t appear to be a specific reason for putting it in front. To be honest, I don’t even think the whole “found” variable is necessary in this function? Maybe some old habits from another language?