Home > php教程 > php手册 > PHP循环语句基础介绍

PHP循环语句基础介绍

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:48:18
Original
834 people have browsed it

for 语句 如果您已经确定了代码块的重复执行次数,则可以使用 for 语句。 语法 for (initialization; condition; increment){ code to be executed;} 注释: for 语句有三个参数。第一个参数初始化变量,第二个参数保存条件,第三个参数包含执行循环所需的增

for 语句

如果您已经确定了代码块的重复执行次数,则可以使用 for 语句。

语法

for (initialization; condition; increment)
{
  code to be executed;
}
Copy after login

注释:for 语句有三个参数。第一个参数初始化变量,第二个参数保存条件,第三个参数包含执行循环所需的增量。如果 initialization 或 increment 参数中包括了多个变量,需要用逗号进行分隔。而条件必须计算为 true 或者 false。

例子

下面的例子会把文本 "Hello World!" 显示 5 次:



<?php for ($i=1; $i<=5; $i++)
{
  echo "Hello World!<br />";
}
?>


Copy after login
Related labels:
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 Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template