";if($i==10){break;}}?>Result: $i=0$i.."/> ";if($i==10){break;}}?>Result: $i=0$i..">

Home  >  Article  >  Backend Development  >  Detailed graphic and text explanation of PHP process control statement expansion

Detailed graphic and text explanation of PHP process control statement expansion

伊谢尔伦
伊谢尔伦Original
2017-06-22 10:55:091127browse

 循环相关的语句:break

表示结束当前的for ,while,do while,switch循环

快速入门

<?php
for($i=0;$i<13;$i++){
echo &#39;$i=&#39;.$i."<br/>";
if($i==10){
break;
}
}
?>;

Detailed graphic and text explanation of PHP process control statement expansion

Detailed graphic and text explanation of PHP process control statement expansion

结果:

$i=0
$i=1
$i=2
$i=3
$i=4
$i=5
$i=6
$i=7
$i=8
$i=9
$i=10

快速入门2 

代码:

<?php
$i=0;
while(++$i){
switch($i){
case 5:
echo "quit at 5<br/>";
break;
case 10:
echo "quit at 10<br/>";
break 2;
default:
break;
}
}
echo &#39;$i=&#39;.$i;
?>

图解:

Detailed graphic and text explanation of PHP process control statement expansion

运行结果:

quit at 5
quit at 10
$i=10

从上面案例看出:我们得:

1,break语句,默认跳出一层

2,break语句后面带的数字,不能超过实际可跳出的循环层数

循环控制语句continue

基本概念:continue用于结束本次循环剩余代码,从新开始新的一次循环

(如果条件为真,就继续执行),continue后面也可以带数字,表示从第几次循环重新开始

快速入门:

代码:

<?php
for($i=0;$i<13;$i++){
if($i==3){
continue;
}
echo &#39;$i=&#39;.$i."<br/>";
}
echo "hello";
?>

图解:

Detailed graphic and text explanation of PHP process control statement expansion

Detailed graphic and text explanation of PHP process control statement expansion

运行结果:

$i=0
$i=1
$i=2
$i=4
$i=5
$i=6
$i=7
$i=8
$i=9
$i=10
$i=11
$i=12
hello

案例2

<?php
for($i=0;$i<2;$i++){
for($j=1;$j<4;$j++){
if($j==2){
continue 2;
}
echo &#39;$i=&#39;.$i.&#39;$j=&#39;.$j."<br/>";
}
}
echo "测试";
?>

结果:

$i=0$j=1
$i=1$j=1

测试

goto语句

基本概念:通过goto语句可以将程序跳转指定的地方去执行

goto 标签;

标签;

语句;

快速入门:

goto a;

echo 'aa';

a:

echo 'bb';

运行结果:

bb

The above is the detailed content of Detailed graphic and text explanation of PHP process control statement expansion. 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