ryanthegecko Posted July 8, 2009 Share Posted July 8, 2009 from a book <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>If...Else</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> </head> <body> <?php for ($i=1; $i<=100; $i++ { echo "I must not use PHP to write my lines." ; } ?> </body> </html> It's throwing up an error saying it expects a ")" on line 16 (the for line) when it's obviously right there!! Any ideas why this isn't working/ Is the book giving me wrong instructions? Help Quote Link to comment https://forums.phpfreaks.com/topic/165218-solved-an-error-in-such-a-simple-piece-of-code-that-i-cant-believe-it/ Share on other sites More sharing options...
Philip Posted July 8, 2009 Share Posted July 8, 2009 for ($i=1; $i<=100; $i++ { Should be: for ($i=1; $i<=100; $i++) { (notice there is no semicolon on the last argument in for) Quote Link to comment https://forums.phpfreaks.com/topic/165218-solved-an-error-in-such-a-simple-piece-of-code-that-i-cant-believe-it/#findComment-871228 Share on other sites More sharing options...
ryanthegecko Posted July 8, 2009 Author Share Posted July 8, 2009 Hey thanks. The book really was teaching me wrong! Is this always the case for "for" - no last semicolon? Why would that be, it seems illogical to me. Quote Link to comment https://forums.phpfreaks.com/topic/165218-solved-an-error-in-such-a-simple-piece-of-code-that-i-cant-believe-it/#findComment-871231 Share on other sites More sharing options...
Philip Posted July 8, 2009 Share Posted July 8, 2009 Yeah, in PHP it will always be like that. Quote Link to comment https://forums.phpfreaks.com/topic/165218-solved-an-error-in-such-a-simple-piece-of-code-that-i-cant-believe-it/#findComment-871234 Share on other sites More sharing options...
Psycho Posted July 8, 2009 Share Posted July 8, 2009 Makes perfect sense. The semicolon is used to delimit the parameters so it only needs to go between the parameters. I have never seen anything like the first example in any language I have used. It is not just a PHP thing. Quote Link to comment https://forums.phpfreaks.com/topic/165218-solved-an-error-in-such-a-simple-piece-of-code-that-i-cant-believe-it/#findComment-871237 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.