Jump to content

a do run run run while a do run run...


stevew

Recommended Posts

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

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.

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. :)

Archived

This topic is now archived and is closed to further replies.

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