Question

I was wondering whether all programs run in a Loop, checking for variable changes then acting upon said changes followed by another Loop. Or do they run in a While statement, waiting for a variable to change before they execute a routine? Or am I just completely wrong?

Was it helpful?

Solution

No, not all programs run in a loop. Interactive programs have a main (message) loop to respond to user input.

Programs also run in some sort of loop (while not Terminated do) when they stay around and wait for input other than user actions. For example HTTP servers that wait for requests to arrive, image processers that wait for files to arrive in a folder, etc.

Programs that take their input parameters, do their thing, report back and then finish, will not run in a loop. That doesn't mean they do not use any loops at all. The work they do may require plenty of loops, but they don't run a loop waiting for more input.

OTHER TIPS

You should learn something about computer science. It will show you that when a program runs, it is the CPU fetch instructions to run. So there is a possibility that cpu do nothing but wait for a intterrupt to wake it up.
The event driven is the best practice nowadays. It costs little and responsive quickly. Though there is not pure event driven os. Linux like OSes use kernel to reponse to interrupts and manage processes by loop-calling schedule method.

“While” is a form of loop. For the scope of your question it would make no difference.

CLI programs usually don't run in a loop. GUI programs usually do. Some have parallel execution flows. I suggest you read the Wikipedia article on event loop so that you grasp the different styles.

Licensed under: CC-BY-SA with attribution
scroll top