One of the “early mistakes” that any programmer makes is creating an infinite loop. Maybe a condition was not correctly set in a while loop. Or maybe some unexpected overflow condition occurred in a for loop.

Infinite loops have always had a bad cognitation for me. However, infinite loops are effectively the backbone of any long-running program. Whether it be apps with a user interface or a server side program, they all effectively use infinite loops to process incoming data.

Consumer apps use loops which listen for any UI interfaction among other data sources. Server side programs can use loops to listen for incoming events such as a new connection and then process data based on those events. Once the event has been processed, the loop starts again and waits for the next event.

Of course, in the technical definition, the run/event loops are not infinite because there are some loop termination conditions (whether it be a process signal or other flag). However, in practice, the expectation is that the programs run in a loop until a user wants to terminate the entire program.

When a programmer encounters an infinite loop the first time, s/he may think of it as something to avoid, but in practice, infinite loops are one of the core building blocks.