mikedj Posted June 6, 2007 Share Posted June 6, 2007 Why won't this For loop do more than one iteration when the While loop is nested inside? Each loop works fine independently, but when I nest them, I only get the first iteration of the for loop. Thanks, Mike <?php $i=0; for ($j=0;$j<2;$j++) { while ($i<10) { echo "\$j = " . $j . "<br/>"; $i++; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54391-solved-while-nested-in-a-for-loop-problem/ Share on other sites More sharing options...
btherl Posted June 6, 2007 Share Posted June 6, 2007 You need to set $i =0 inside the outer loop, otherwise it will not be reset for the second time the inner loop runs. Quote Link to comment https://forums.phpfreaks.com/topic/54391-solved-while-nested-in-a-for-loop-problem/#findComment-268961 Share on other sites More sharing options...
mikedj Posted June 6, 2007 Author Share Posted June 6, 2007 It seems so obvious now that you've pointed out the problem, but I just couldn't see it on my own. I very much appreciate the help. Thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/54391-solved-while-nested-in-a-for-loop-problem/#findComment-269037 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.