Loops probably aren’t new to most readers here. Yet, they are used in some less obvious scenarios.
The following is by my understanding.
Probably a lot of us have written a program that finds a number to a certain exponent. Therein, one might use a loop to continue multiplying the starting value by itself until it’s done so the exponent number of times. Then, the loop exits and the program tells the result.
For me, learning programming, the loop idea like above was straightforward enough. It became obvious why some operations needed to be repeated until a certain condition was reached. I came to really like loops and what they could do.
When I learned that input devices, such as a PC or smartphone, or even a calculator, typically use a loop to discover if the user has entered something, I was surprised. It seems a background loop is always running: during said cycle, the device checks every potential input, such as the keys and the ports, for activity. Detecting activity, it responds. Else, it “waits” by just continuing the loop.
I wondered about the reason for the looping design, but it seems it’s because it simplifies the question of which key or port is being triggered that instant. The device discovers the key press, for instance, when it checks if that key is pressed as part of its routine loop. Finding it is pressed, it knows which key has been activated because of the position in the loop when the impulse was discovered.
With the speed of computers, it’s easy to tell which key was pressed first, etc. Let’s imagine a “low” scan rate of 125Hz. That means 125 times per second the computer checks each key to see if it’s pressed.
Interesting, eh?
Source:
akkogear.eu (Dec 26, 2025). “Keyboard Scan Rate Explained: What You Need to Know.”