We all know what a loop is: a programming language statement that allows us to repeat the execution of a piece of code until a certain ending condition is met. If the ending condition is never met or it does not exist at all, the loop never ends: that’s an infinite loop (also known as an endless loop).
To willingly produce an infinite loop in PHP you can use a while statement with true or 1 instead of the ending condition:
while (true) { } |
or an empty for statement:
for (;;) { } |
When in need of very long loops we sometime use infinite loops in our code but more frequently we use pseudo-infinite loops, which are loops that appear to be infinite but eventually end sometime:
while (true) { //some code if (date('m-d')>'12-25') break; } //appears to be infinite but force ends on Christmas :) |
Tip: you may find force ending conditions very useful when debugging code.

Recent Comments