Why do we need to write the !IsStopped() function inside many indicators "For" Loops?

 

Human has clicked close chart, close window, remove indicator, etc.

Indicators run in the terminal thread. Until all related indicators return, nothing else can happen - the terminal appears dead.

If you don't terminate your long loops early - the terminal appears dead.

 

In other languages, like python for example, you can create infinite loops 

while True:
    pass

...and a stoppage like a keyboard interrupt will raise an exception which will stop the program. MQL doesn't offer exception handling so you must program everything explicitly. Therefore, if you wanted an infinite loop for MQL you need to check the program's stopped flag each iteration so you won't freeze up the terminal like whroeder says. So anytime you have an indefinite loop or long-running blocking functions in the body of the loop then make sure to add the IsStopped

while (true);

while (!IsStopped());
Reason: