|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2005-07-13 10:32 UTC] richard dot quadling at bandvulc dot co dot uk
 Description:
------------
The do-while control structure mentions the use of break in a do-while loop, but does not say if it is supported in PHP or not.
The manual reads ...
"Don't worry if you don't understand this right away or at all. You can code scripts and even powerful scripts without using this 'feature'."
When it says I can code without this "feature" does this mean I do not need to use this "feature", because I don't understand the "feature", or I cannot use this "feature", because this "feature" is not supported?
I think the issue is that at the top of the page for do-while there is a statement ...
"There is just one syntax for do-while loops:"
Initially, I thought that the documentation meant that this "feature" was not available in PHP.
It is available in PHP5.0.4 (as seen by the code below - cli code).
Reproduce code:
---------------
<?php
echo "About to enter a while loop with a break.\n";
$iCount = 0;
$iBreakOn = 10;
while(True)
	{
	++$iCount;
	echo "Counted to $iCount\n";
	if ($iCount === $iBreakOn)
		{
		break;
		}
	}
echo "While loop exited with $iCount.\n";
echo "About to enter a do-while loop with a break.\n";
$iCount = 0;
$iBreakOn = 10;
do
	{
	++$iCount;
	echo "Counted to $iCount.\n";
	if ($iCount === $iBreakOn)
		{
		break;
		}
	}
while(True);
echo "While loop exited with $iCount.\n";
?>
Actual result:
--------------
About to enter a while loop with a break
Counted to 1
Counted to 2
Counted to 3
Counted to 4
Counted to 5
Counted to 6
Counted to 7
Counted to 8
Counted to 9
Counted to 10
While loop exited with 10
About to enter a do-while loop with a break
Counted to 1
Counted to 2
Counted to 3
Counted to 4
Counted to 5
Counted to 6
Counted to 7
Counted to 8
Counted to 9
Counted to 10
While loop exited with 10
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 13:00:01 2025 UTC | 
I think the documentation is pretty clear. The example is in *PHP* and it demonstrates the use of a do{} while with breaks. It says that there's just one syntax for do-while, which is correct. For example, 'if' has a lot more (if-endif).