Jump to content

loop question


jimfog

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...