A
A
Andabad2020-11-14 22:00:36
C++ / C#
Andabad, 2020-11-14 22:00:36

How to distinguish an infinite loop from a very long one?

Hello! We at the university suffer from the processing of experimental data using the C language. As a result, self-written calculation programs can contain loops with a large number of iterations (up to 1000). Question on compilation and debugging. Are there any cool tricks on what to output to the terminal, for example, to distinguish a long loop from an endless loop?? You have to do something, but you're afraid to lose your computer. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dollar, 2020-11-14
@Andabad

In general, no way.
But you can somehow display the progress of calculations in real time. For example, how many percent of the calculations have already been completed. Then the bugs will be easier to notice.
Or you can display how one stage replaces another (provided that there will be something new in the new round and progress will be visible ). For example, reading 1000 files may be followed by the output of the file name. And thus it is clear that the program moves from one file to another, and is not stuck somewhere.
But of course there is no guarantee. Even so, it can go in cycles indefinitely. It will just be easier to detect - progress freezing, repeating stages, incomprehensible progress jumps, etc.

G
Griboks, 2020-11-14
@Griboks

This is a classic stopping task. It is not solved algorithmically. Therefore, you will never know the answer until you check each specific case.
Rearrange your algorithm so that it no longer has the theoretical possibility of infinite execution. To do this, first of all, get rid of the recursion.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question