Home  >  Article  >  Backend Development  >  What is the usage of php do while

What is the usage of php do while

PHPz
PHPzOriginal
2020-09-25 15:46:133377browse
php do while is a loop statement that is guaranteed to be executed once. Its usage syntax is such as [fd630b5bddfea94b823000e498777068 0); ?>], its loop statement will be run exactly once.

What is the usage of php do while

do-while

(PHP 4, PHP 5, PHP 7)

do-while loop Very similar to a while loop, except that the value of the expression is checked at the end of each loop rather than at the beginning. The main difference from a normal while loop is that the do-while loop statement is guaranteed to be executed once (the truth value of the expression is checked after each loop), but in a normal while loop this is not necessarily the case (the truth value of the expression Checked at the beginning of the loop, if it is FALSE at the beginning, the entire loop terminates immediately).

There is only one syntax for do-while loops:

 0);
?>

The above loop will run exactly once, because after the first loop, when the truth value of the expression is checked, its value is FALSE ($i is not greater than 0) causing the loop to terminate.

Experienced C language users may be familiar with a different do-while loop usage, which puts the statement inside do-while(0) and uses a break statement inside the loop to end the execution loop. The following code snippet demonstrates this approach:

Don’t worry if you don’t understand it right away. You can still write powerful code without using this "feature". Since PHP 5.3.0, you can also use goto to break out of loops.

The above is the detailed content of What is the usage of php do while. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn