


The previous article introduced you to "Detailed explanation and examples - for loop (and the difference between while loop)". This article continues to introduce to you the selected flow control statements--break statement and continue statement. (With detailed explanation), don’t hesitate to come in and learn! You will definitely gain something! ! !
1: break statement
Function:
You can use break in switch to terminate the execution of the branch structure;
You can use break in any loop structure to terminate the loop operation;
We will explain the specific structure by code operation. The code is as follows:
<?php /******break 语句******/ //break测试 输出10个hr for($hr =0;$hr <10; $hr ++){ echo $hr. '<hr/>'; if($hr == 4){ break; } } ?>
The code running result is as follows:
Note:
The break statement can be followed by parameters. The meaning of break1 is the same as break. If the break2 statement is set in the reloop to terminate the two-layer loop (nested loop)
For the specific structure, we use the code Operation explanation, the code is as follows:
<?php /******break 语句******/ //break测试 输出10个hr for($hr =0;$hr <10; $hr ++){ echo $hr. '<hr/>'; if($hr == 4){ break; } } for($i =0;$i <10; $i ++){ for ($j=0;$j<10;$j++){ echo$j. ''; if($j== 4){ break 2; } } echo '<br/>'; } ?>
The code running result is as follows:
After understanding the break statement, we then understand the continue statement:
Continue function: Recycle the loop structure to terminate this cycle and start the next cycle;
We will explain the specific structure with code operations. The code is as follows:
<?php //continue for($i=0;$i<10;$i ++){ if($i == 4){ continue; } echo $i;//0 1 2 3 5 } ?>
The code running result is as follows:
continue statement
Note:continue can be followed by numerical parameters. continue1 means the same as continue. If continue2 is set in a reloop, it means jumping to the outer layer to continue the loop (nested loop)
We will explain the specific structure with code operations. The code is as follows :
<?php //continue for($i=0;$i<10;$i ++){ if($i == 4){ continue; } echo $i;//0 1 2 3 5 } for($i =0;$i <10; $i ++){ for ($j=0;$j<10;$j++){ if($j== 4){ continue 2; } echo$j. ''; } echo '<br/>'; } ?>
The code running results are as follows:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Selected flow control statements--break statement and continue statement (with detailed explanation). For more information, please follow other related articles on the PHP Chinese website!

continue是跳出当前循环。continue语句用于跳过本次循环,执行下次循环;当遇到continue语句时,程序会立即重新检测条件表达式,如果表达式结果为真则开始下次循环,如果表达式结果为假则退出循环。

PHP中continue关键字的作用和使用方法在PHP编程中,continue是一个非常有用的关键字。它用于控制循环语句的执行流程,允许跳过当前循环中的剩余代码,并直接进入下一次循环的执行。continue的作用是在循环语句中跳过当前迭代中的代码,并直接开始下一次迭代。当执行到continue语句时,循环控制会立即转到循环体的开始处,而不会执行continu

在Go语言中,break停止语句用于循环语句中跳出循环,并开始执行循环之后的语句。break语句可以结束for、switch和select的代码块,另外break语句还可以在语句后面添加标签,表示退出某个标签对应的代码块,标签要求必须定义在对应的 for、switch和select的代码块上。

在之前的文章中,我们带大家学习了JS中的几种循环控制结构(while和do-while循环、for循环),下面聊聊跳出循环语句break和continue,希望对大家有所帮助!

在php中,break用于跳出当前的语法结构,执行下面的语句;可以在switch、for、while和do while等语句中使用,可以终止循环体的代码并立即跳出当前的循环,执行循环之后的代码。break语句可以带一个参数n,表示跳出循环的层数,如果要跳出多重循环的话,可以用n来表示跳出的层数,如果不带参数默认是跳出本重循环。

在PHP中使用switch语句来进行多个分支的选择是很常见的,通常在每个分支结束后会使用break语句来退出switch语句。然而,有些情况下我们不想使用break语句,本文将介绍在PHP switch语句中不使用break的情况。

说明1、break的作用是跳出现在的循环块(for、while、dowhile)或程序块(switch)。2、循环块的作用是跳出现在循环中的循环体。程序块中的作用是中断和下一个case条件的比较。在switch语句中使用break,终止switch语句。当break用于循环时,跳出循环。在其他地方使用break是没有意义的。实例intsum=0;inti;for(i=1;i

PHP中break语句的用法详解在PHP编程中,break语句是一个非常常用的控制语句,它通常用于中断循环或者switch语句的执行。在本文中,我们将详细解释break语句的用法,并给出具体的代码示例。1.中断循环在循环中使用break语句可以提前中断循环的执行,跳出循环体。这在某些情况下非常有用,比如在满足某个条件时就不再需要继续循环。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!
