Home> headlines> body text

How to use php while loop

无忌哥哥
Release: 2018-06-28 10:08:11
Original
2765 people have browsed it

* while loop

* 1. Entry judgment: while(condition){ #code }

* 2. Exit judgment: do { #code } while(condition)

echo '

while循环


'; for ($i=0; $i<10; $i++) { echo $i<9 ? $i.',' : $i; } echo '
';
Copy after login

//Use while to implement the above functions

//1. Entry judgment: judge whether the condition is successful before entering the loop, it is possible not to do it once

$i = 0; //初始条件 // $i = 10; //初始条件改为10,一次都不会执行 while ($i<10) { //循环条件 echo $i<9 ? $i.',' : $i; $i++; //更新条件,如果没有将进和死循环 } echo '
';
Copy after login

//2 .Exit judgment: judge whether the condition is successful after the loop execution ends, and execute the loop body at least once

$i = 0; //初始条件 // $i = 10; //初始条件改为20,但仍会执行一次 do { echo $i<9 ? $i.',' : $i; $i++; //更新条件,如果没有将进和死循环 } while ($i<10); //循环条件
Copy after login
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!