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

Application of break statement in PHP

巴扎黑
巴扎黑Original
2016-12-28 17:39:321419browse

一 实例

<!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>使用break关键字跳出多重循环</title>
<style type="text/css">
<!--
body {
background-color: #CCFF00;
}
-->
</style></head>
<body>
<?php
while(true){
for(;;){
for($i=1;$i<=4;$i++){
echo $i." <img  src=&#39;images/$i.jpg&#39; alt="Application of break statement in PHP" >"."\t";
if($i == 3){
echo "<p>变量\$i等于3,跳出一重循环。<p>";
break 1;
}
}
for($j = 1; $j < 5; $j++){
echo $j." <img  src=&#39;images/$j.jpg&#39; alt="Application of break statement in PHP" >"."\t";
if($j == 4){
echo "<p>变量\$j等于4,跳出最外重循环。";
break 3;
}
}
}
echo "看不到我吧,呵呵!";
}
?> 
</body>
</html>

二 运行结果

Application of break statement in PHP

三 注意事项

本实例共3层循环,最外层的while循环和中间的for循环是无限循环,最里面并列两个for循环:程序首先执行第1个循环,循环3次,跳出当前循环(一重循环),然后继续执行第二个for循环,循环4次,然后跳出最外层的循环(体会break后的数字的含义,跳出针对自己的第3层循环)。


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