count the number of loops to prevent an endless loop and to abort after a while automatically