Home  >  Article  >  Backend Development  >  Application of continue statement in PHP

Application of continue statement in PHP

巴扎黑
巴扎黑Original
2016-12-28 17:37:421510browse

One example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>使用continue关键字控制流程</title>
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
body {
margin-left: 10px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
background-color: #CCFF33;
}
-->
</style></head>
<body>
<?php
$arr = array("PHP程序开发范例宝典","PHP开发典型模块大全","PHP函数参考大全","PHP项目开发全程实录","PHP从入门到精通","PHP网络编程自学手册");//声明一个数组变量$arr
for($i = 0; $i < 6; $i++){//使用for循环
echo "<br>";
if($i % 2 == 0){//如果$i的值为偶数,则跳出本次循环
continue;
}
for(;;){//无限循环
for($j = 0; $j < count($arr); $j++){//再次使用for循环输出数组变量
if($j == $i){//如果当前输出的数组下标等于$i
continue 3;//跳出最外重循环
}else{
echo $arr[$j]."\t | ";//输出表达式
}
}
}
echo "你永远都看不到我噢!";
}
?>
</body>
</html>

Second running result

Application of continue statement in PHP

Three code analysis

for implements 6 loops, in which the first, For loops 3 and 5, for the 1st loop, a string is output, for the 3rd loop, 3 strings are output, and for the 5th loop, 5 strings are output. Pay attention to understand the meaning of continue 3 and jump to the third level of loop.


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