# Measuring infinite loops [closed]

Theoretically, is there a way to measure how many infinite loops are running at a given point in time? In other words, is there a way to freeze everything and get a number on how many infinite lines of code are running on every machine.

• I'm not sure how to make sense of this question. – Yuval Filmus Oct 5 '18 at 7:27
• Maybe I worded it wrong. When you execute a program, some type of loop runs right? I was wondering if there is a way to basically see how many programs are running at once across all devices connected to the internet. I am sure it is in the trillions but I was just curious. – Cody Rutscher Oct 5 '18 at 8:52

While I don't think your question is fitting for cs.StackExchange, let me try to answer it anyway:

You would approach this problem as follows:

1. To answer how many infinite loops run on all devices, you would need to determine the number of infinite loop on each device
2. To determine the number of infinite loops on each device, you would have to count all loops running on each device and then determine if they will be running forever
3. The last step would require a method that determines for a given loop if it will run forever. Assuming you had such a method, you could do the following:

a.) Take any piece of code, $$\Pi$$

b.) Put it into a loop of the form: "$$\text{do} \{\ \Pi\ \}\ \text{while}\ (false);$$" As the resulting expression is a loop, you could feed it to your loop-decision method to find out if it terminates.

c.) The loop will terminate, if and only if $$\Pi$$ terminates. As you can take any $$\Pi$$ you want, you would thus be able to solve the Halting problem, which is proven to be impossible.