Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
py-quickstart/docs/Iteration/while-loops/example-2.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
14 lines (14 sloc)
398 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example-2.py | |
# Search and index | |
pet = ["dog", "cat", "rabbit", "snake", "octopus", ] | |
search = "buffalo" | |
i = 0 | |
while i < len(pet): | |
if pet[i] == search: | |
# we would have found search in pet | |
print(f"We found the search term in index {i}.") | |
break | |
i += 1 | |
else: | |
# We didn't find the search item in the list | |
print("We didn't find the search term!") |