+ 5

What is the flow of code in a nested for loop? (see description)

in the code below which loop runs first inner or outer( according to my understanding inner than outer than again inner than outer and so on until it reaches the limit given but... it should stop when it prints three stars as after that value of b is not greater than value of a. <?php for($a = 1; $a <=5; $a++){ for($b = 5; $b>=$a; $b--){ echo "*"; } echo "<br/>"; } ?> /* OUTPUT ***** **** *** ** * outpu*/

9th Dec 2017, 3:58 PM
Bilal Asghar
Bilal Asghar - avatar
1 Odpowiedź
+ 12
1. iteration: a = 1, b = 5, 4, 3, 2, 1 2. iteration: a = 2, b = 5, 4, 3, 2 3. iteration: a = 3, b = 5, 4, 3, 4. iteration: a = 4, b = 5, 4, 5. iteration: a = 4, b = 5
9th Dec 2017, 4:05 PM
Vukan
Vukan - avatar