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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.