Jump to content

simple for loop


RLJ

Recommended Posts

Hi all, I have the following very simple for loop:

 

$i=1;
                    for ($i<26)
                    {
                        if (preg_match("~.~",$profile3["exp$i"])==1){echo $profile3["exp$i"],"<br />";}
                        $i++;
                    }

 

However, it's not working and gives me the following error message:

Parse error: parse error, expecting `';'' in ......... on line X

where X is the line with " for ($i<26) ".

 

Can somebody pls see where I've gone wrong? (prob a very stupid mistake, but I can't spot it)

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/228834-simple-for-loop/
Share on other sites

You are not using the correct parameters for a for() loop - perhaps you meant to use a while() loop.

 

You can do one of the following:

 

for() loop

for ($i=1; $i<26; $i++)
{
    //Run code inside loop
    //$i will be incremented automatically
}

 

while() loop

//Define $i
$i = 1;
while($i<26)
{
    //Run code inside loop
    //$i need to be incremented in the loop
    $i++;
}

Link to comment
https://forums.phpfreaks.com/topic/228834-simple-for-loop/#findComment-1179693
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.