Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Infinite Loop

An infinite loop never ends, unless an external event make it break out of itself.

Infinite loops are usually un wanted, and should be avoided. They happen when an exit condition is forgotten, omitted or tests a stationary aspect of the loop. That way, the loop keeps repeating.

PHP prevents infinite loop automatically, by enforcing the max_execution_time or memory_limit error.

Infinite loop are also a base structure in event loops: the code waits for an event by repeating itself, with a time moderation to avoid wasting too much energy. As such, it is a feature.

Such loops are related to polling, which is a process where a resource is checked on a regular basis for udpates. They may be replaced by hooks or streams.

<?php

    // infinite loop while
    while(true) { }
    
    // infinite loop while
    do { } while(1);
    
    for(;;) {} 

?>

Documentation

See Also