首頁  >  文章  >  後端開發  >  PHP中continue語句的應用

PHP中continue語句的應用

巴扎黑
巴扎黑原創
2016-12-28 17:37:421510瀏覽

一實例

<!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>

二運行結果

PHP中continue語句的應用

三程式分析

for實現6次循環,其中處理第1,3,5次循環,針對第1次循環,輸出一個字串,針對第3次循環,輸出3個字串,針對第5次循環,輸出5個字串。注意體會continue 3的意義,跳到第三層循環。


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn