05-12-2008, 12:00 AM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Oct 2007
Location: Manchester, UK
Posts: 422
Thanks: 22
|
A nested loops is a loop that has a loop within it. First of all the outer loop's first iteration triggers the inner loop then the inner loop continues until completion, then the outer loop cycles again thus causing the inner again to trigger again.
put into a simple example:
PHP Code:
for($i=0;$i < 10; $i++) { echo 'Line ', $i + 1, ' '; for($j=0; $j < 5; $j++) { echo $j; } echo '<br />'; }
outputs :
Code:
Line 1 01234
Line 2 01234
Line 3 01234
Line 4 01234
Line 5 01234
Line 6 01234
Line 7 01234
Line 8 01234
Line 9 01234
Line 10 01234
basically the first loop out puts : 'Line 1' then the nested loop starts and echos numbers 0-4, then the first loop echos 'Line 2' then triggers the nested loop again and the cycle continues until the first loop finishes.
hope i made that helps
__________________
|
|
|
|