stevew Posted July 20, 2012 Share Posted July 20, 2012 Removing the ; in these while and do while snippets is resulting in different outputs...can someone explain what effect this is having in each? thanks. http://writecodeonline.com/php/ while ($value < 10); while ($value < 10) <?php $value =20; while ($value < 10); { $value *=2; echo $value, "<br>"; } ?> output: 40 <?php $value =20; while ($value < 10) { $value *=2; echo $value, "<br>"; } ?> output: none <?php $value =20; do{ echo $value, "<br>"; $value *=2; } while ($value < 10); ?> output: 20 <?php $value =20; do{ echo $value, "<br>"; $value *=2; } while ($value < 10) ?> output: Parse error Quote Link to comment https://forums.phpfreaks.com/topic/266002-a-do-run-run-run-while-a-do-run-run/ Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 The semicolon terminates the statement. The curly braces are ignored, and the rest of the code is run procedural, top to bottom. The do...while(); needs a semicolon to terminate the statement. A semi-colon is a very, very important language structure, and changing it's position will have a dramatic effect on the way your code works, or cause it to not work at all. If you'd like a more specific response, narrow your question down to a single example you're curious about. Quote Link to comment https://forums.phpfreaks.com/topic/266002-a-do-run-run-run-while-a-do-run-run/#findComment-1363056 Share on other sites More sharing options...
stevew Posted July 20, 2012 Author Share Posted July 20, 2012 The semicolon terminates the statement. The curly braces are ignored, and the rest of the code is run procedural, top to bottom. The do...while(); needs a semicolon to terminate the statement. A semi-colon is a very, very important language structure, and changing it's position will have a dramatic effect on the way your code works, or cause it to not work at all. If you'd like a more specific response, narrow your question down to a single example you're curious about. No that's great thanks...I was just looking for a general explanation. Quote Link to comment https://forums.phpfreaks.com/topic/266002-a-do-run-run-run-while-a-do-run-run/#findComment-1363073 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.