Solution: Print all the locations in a string
Basically you need to call loc = text.find("c", loc + 1) but that looks strange. How can you use loc (as a parameter of the function) and also assign to it. However programming languages don't have a problem with this as the assignment happens after the right-hand-side was fully executed.
The problem that now you have two different calls to find. The first one and all the subsequent calls.
How could we merge the two calls?
The trick is that you need to have an initial value for the loc variable and it has to be -1, so when we call find for the first time, it will start from the first character (index 0).
examples/loops/find_loop_one.py
text = "The black cat climbed the green tree." loc = -1 while True: loc = text.find("c", loc+1) if loc == -1: break print(loc)
examples/loops/find_loop.py
text = "The black cat climbed the green tree." start = 0 while True: loc = text.find("c", start) if loc == -1: break print(loc) start = loc + 1