Hello! I’m a little stuck on this problem. It looks like my for loop only does one iteration? Just looking for some guidance.
If the first item in
contacts) is not the contact you’re looking for, then your code returns “No such contact”. Always remember that a function stops executing as soon as it hits a return statement.
I was doing that last night and I got so confused when I was searching for Alice. One will say I found it, the other one says no can’t find it, but is the same name.
I personally don’t like using break.
The loops does do exactly what you think is doing.
The loop breaks out as soon as it finds a match. So if the search found the name on the first iteration, it will stop at first iteration.