RLJ Posted February 25, 2011 Share Posted February 25, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/228834-simple-for-loop/ Share on other sites More sharing options...
Psycho Posted February 25, 2011 Share Posted February 25, 2011 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++; } Quote Link to comment https://forums.phpfreaks.com/topic/228834-simple-for-loop/#findComment-1179693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.