Проектирование цикла. У меня есть такой дизайн цикла For, который представляет собой итеративный цикл для подбора переменной "value_to_check"
Код: Выделить всё
my_list = [1, 2, 3, 4, 5]
value_to_check = 4
for item in my_list:
if value_to_check == item:
print("Match found: ", item)
break
else:
print("No match found")
Код: Выделить всё
my_list = [1, 2, 3, 4, 5]
value_to_check = 3
index = 0
guessed = False
while not guessed and index < len(my_list):
if value_to_check == my_list[index]:
print("Match found: ", my_list[index])
guessed = True
break
else:
index += 1
else:
print("No match found")
Подробнее здесь: https://stackoverflow.com/questions/790 ... -practices