This is impossible. Read up on the halting problem.
Also, even if it were possible in theory, or even if you just want to do some sort of heuristic guess, you obviously can't do it by just running the file. If the program has an infinite loop, you will run the infinite loop and get stuck in it, so you'll never get a chance to check your counter.