B
B
Brutus12020-08-03 16:47:22
Python
Brutus1, 2020-08-03 16:47:22

How to count looping and stop code execution in such cases?

In general, there is a piece when, which inevitably loops under certain circumstances (not because of the code).
The question is, what and where to add, so that the function, with an infinite looping of a certain one, whilesimply issues breakor Let's assume such a function:return False

def func():
  a = 0 #точка А
  while a<0:
    #разного рода код
    #куча if-else
  b = 1 #точка Б


How to get from point A to point B? and only under the condition that inside while some segment was repeated several times in a row.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PavelMos, 2020-08-03
@Brutus1

Insert a counter before the start of the while, increase it by 1 in the while and thus check the number of cycles for exceeding the number of repetitions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question