Code Inspection: Loop does not iterate
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.
Suppress an inspection in the editor
Place the caret at the highlighted line and press Alt+Enter or click .
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.