PhpStorm
 
Get PhpStorm
You are viewing the documentation for an earlier version of PhpStorm.

Code Inspection: Loop does not iterate

Last modified: 16 May 2022

Reports the loop statements whose bodies will execute at most once.

The inspection does not report foreach loops with a key or value used inside the loop body. Commonly, such loops are intended to perform an action only on their first iteration (for example, get the first element of an array).

In the following example, the for loop is reported by the inspection, since the loop's body is only executed once and then terminated by the break statement.

In the following example, the foreach loop is not reported by the inspection, since it is legitimately used to obtain the first element in an array.