1.2.762. Nested Loops¶
Nested loops happens when a loop (while, do..while, for, foreach), is used inside another loop. Such structure tends to require a lot of processing, as the size of both loops have to be multiplied to estimate the actual payload. They should be avoided as much as possible. This may no be always possible, though.
Nested loops are worth a check for performances reasons, as they will process a lot of times the same instructions.
<?php
// Nested loops
foreach($array as $a) {
foreach ($letters as $b) {
// This is performed count($array) * count($letters) times.
doSomething();
}
}
?>
1.2.762.1. Connex PHP features¶
1.2.762.1.1. Specs¶
Short name |
Structures/NestedLoops |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Available in |