jimfog Posted January 25, 2012 Share Posted January 25, 2012 Despite i am going to ask a general(crucial though) loop question i am going to use a specific example. Here is the example: for ($i = 0; $i < ($maxday + $startday); $i++) When this loop first starts the i begins from 0 or from 1? Or it starts from 1 on the second run? Link to comment Share on other sites More sharing options...
Ingolme Posted January 25, 2012 Share Posted January 25, 2012 I starts as 0. Link to comment Share on other sites More sharing options...
Don E Posted January 25, 2012 Share Posted January 25, 2012 and the second start should be 1. Link to comment Share on other sites More sharing options...
thescientist Posted January 25, 2012 Share Posted January 25, 2012 Despite i am going to ask a general(crucial though) loop question i am going to use a specific example. Here is the example:for ($i = 0; $i < ($maxday + $startday); $i++) When this loop first starts the i begins from 0 or from 1? Or it starts from 1 on the second run? it could be as simple as adding some basic debugging $loopCounter = 1; for ($i = 0; $i < ($maxday + $startday); $i++){ echo 'loop iteration #' . ++$loopCounter . '<br>'; echo 'i is => ' . $i . '</br>';}; Link to comment Share on other sites More sharing options...
Ingolme Posted January 25, 2012 Share Posted January 25, 2012 it could be as simple as adding some basic debugging $loopCounter = 1; for ($i = 0; $i < ($maxday + $startday); $i++){ echo 'loop iteration #' . ++$loopCounter . '<br>'; echo 'i is => ' . $i . '</br>';}; You should use $loopCounter++ or it's going to start at 2. Link to comment Share on other sites More sharing options...
jimfog Posted January 25, 2012 Author Share Posted January 25, 2012 thanks and thanks...I am trying to debug a code segment-where the above loop is contained- and is difficult to pinpoint the exact location of the error.I have to look every code detail again and again.I might make a post for it...for now I am still trying Link to comment Share on other sites More sharing options...
thescientist Posted January 25, 2012 Share Posted January 25, 2012 You should use $loopCounter++ or it's going to start at 2. oh right. or have it start at 0. good catch. Link to comment Share on other sites More sharing options...
jimfog Posted January 26, 2012 Author Share Posted January 26, 2012 I just find where the problem is-using variable debugging is EXTREMELY HELPFUL. Having to figure out what each variable outputs is very cumbersome, using echos though, to actually see, what really do they output in the browser is a very good way of finding problems in the code.. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.