#python #python-3.x #while-loop #conditional-statements
#python #python-3.x #цикл while #условные операторы
Вопрос:
Есть ли определенный способ, которым я могу проверить, по-прежнему ли выполняется условие цикла while внутри цикла в Python? Что-то вроде этого:
i = 0
while i < 2:
i = 2
evalcond
print("This executes because the condition is still true at this point")
Возможно ли это?
Комментарии:
1. Похоже, вам нужна структура
while 1:
иif:... break
.
Ответ №1:
Возможно, что-то вроде этого?
i = 0
while i < 2:
i = 2
if i >= 2:
break
print("This executes because the condition is still true at this point")
Ответ №2:
Если вы хотите избежать использования break
, вы также можете сделать это
i = 0
while i < 2:
i = 2
if i < 2:
print("This executes because the condition is still true at this point")