Home  >  Article  >  Backend Development  >  Methods and simple examples of while loop control in php

Methods and simple examples of while loop control in php

墨辰丷
墨辰丷Original
2018-06-02 09:37:211624browse

This article mainly introduces the while loop control method and simple examples in php. Interested friends can refer to it. I hope it will be helpful to everyone.

The while loop is the simplest loop in PHP. Its basic format is:

while (expr){ 
  statement 
}

or

while (expr): 
  statement 
endwhile;

This syntax indicates that as long as the expr expression is TRUE, the statement will be executed until expr is FALSE. The statement indicates the action or logic to be executed.

<?php 
$i = 1; 
while ($i <= 10) { 
  echo $i; 
  $i++; 
} 
?>

This example loops out 1 to 10.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

The reasons and solutions for the discontinuity of ID settings in PHP after they are incremented

PHP implementation judgment Method for mobile devices

PHP strip_tags() Strips the HTML tags in the string

The above is the detailed content of Methods and simple examples of while loop control in php. 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