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 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. 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. 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
Archived
This topic is now archived and is closed to further replies.