Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For loop not working

Status
Not open for further replies.

KempCGDR

Programmer
Jan 10, 2003
445
GB
I have the following piece of code :

Code:
for ($i = 1; $i == $slashcount; $i++) {
    $extrapath .= "..f";
    echo $extrapath.'<br>'.$i.'<br>';
}

the loop will only execute once when $slashcount starts equal to $i. Any other value (smaller or larger) and the loop doesn't even execute once. I've checked php.net and etc with no luck, can anyone see the problem?
 
Yes.

It's your use of &quot;==&quot; as the test operator.

The only time the loop can execute is when i$ does, indeed, equal $slashcount. What you have there is the functional equivalent of an if statement.

Generally, the test condition of a for loop is greater than or less than.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Doh, was thinking of that as the statement to get out of the loop. Don't know how I managed that one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top