Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use breakout statement in php

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "how to use the breaksentence in php". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use breaksentences in php" can help you solve your doubts.

In php, break statements can be used in statements such as switch, for, while and do while to terminate the code of the loop body and immediately jump out of the current loop and execute the code after the loop; you can also specify several layers of loops, syntax "break n;", and the parameter n specifies the number of layers of loops to jump out.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

The break keyword allows the program to jump out of the current loop and can be used in statements such as switch, for, while, and do while, which terminates the code in the body of the loop and immediately jumps out of the current loop and executes the code after the loop.

The execution flow of the break keyword is shown in the following figure:

Break keyword execution process

[example]

In the for loop, the loop is terminated when the current value of $I is determined to be 3. The execution result of the code is:

012

The effect is the same in while, do while, and foreach loop statements, and the function of the break statement is to terminate the loop.

Description:

The break statement can not only jump out of the current loop, but also specify several layers of loop to jump out. The syntax format is:

Break n

Where the parameter n specifies the number of layers of the loop to jump out

Example:

The running results are as follows:

The variable $I is equal to 3, which jumps out of the first cycle. $j = 0 ~ (th), j = 1 ~ (th) j = 2 ~ (th), j = 3 ~ (th), j = 4

The variable $j equals 4, jumping out of the outermost loop.

After reading this, the article "how to use breaksentences in php" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report