Usage analysis of break and continue
Introduction to the usage of break and continue:
(recommended learning: java entry program)
break
1. Break is used in a switch statement to terminate the switch statement;
2. When break is used in a loop, it jumps out of the loop;
(1) break is used In the switch statement, terminate the switch statement
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Execution result:
(2) break When used in loops, jump out of the loop
Example:
1 2 3 4 5 6 |
|
Execution result:
(Video tutorial recommended : java video tutorial)
continue
continue is used in a loop to jump out of this loop and continue to execute the next loop;
Example:
1 2 3 4 5 6 |
|
Execution result:
You can see that when i=5, the continue key is encountered word, jump out of this loop, and continue to execute the loop after i=6.
The above is the detailed content of Usage analysis of break and continue. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



The role and use of the continue keyword in PHP In PHP programming, continue is a very useful keyword. It is used to control the execution flow of loop statements, allowing to skip the remaining code in the current loop and directly enter the execution of the next loop. The function of continue is to skip the code in the current iteration in the loop statement and start the next iteration directly. When the continue statement is executed, loop control will immediately go to the beginning of the loop body without executing continue.

continue is to jump out of the current loop. The continue statement is used to skip this loop and execute the next loop; when encountering the continue statement, the program will immediately recheck the conditional expression. If the expression result is true, the next loop will start. If the expression result is false, Exit the loop.

It is very common to use switch statements to select multiple branches in PHP. Usually, a break statement is used to exit the switch statement after each branch. However, there are situations where we do not want to use the break statement. This article will introduce the situation of not using break in the PHP switch statement.

Note 1. The function of break is to jump out of the current loop block (for, while, dowhile) or program block (switch). 2. The function of the loop block is to jump out of the loop body currently in the loop. The function of the program block is to interrupt and compare the next case condition. Use break in a switch statement to terminate the switch statement. When break is used in a loop, it breaks out of the loop. There is no point in using break elsewhere. Example intsum=0;inti;for(i=1;i

In the previous article, we took you to learn several loop control structures in JS (while and do-while loops, for loops). Let’s talk about the break and continue statements to jump out of the loop. I hope it will be helpful to everyone!

In PHP, break is used to jump out of the current syntax structure and execute the following statements; it can be used in statements such as switch, for, while, and do while. It can terminate the code of the loop body and jump out of the current loop immediately, and execute the following statements after the loop. code. The break statement can take a parameter n, which represents the number of levels to jump out of the loop. If you want to jump out of multiple loops, you can use n to represent the number of levels to jump out of. If there is no parameter, the default is to jump out of the current loop.

In the Go language, the break stop statement is used to jump out of the loop in a loop statement and start executing the statement after the loop. The break statement can end the code blocks of for, switch and select. In addition, the break statement can also add a label after the statement to indicate exiting the code block corresponding to a certain label. The label requirement must be defined on the corresponding code block of for, switch and select. .

The role and precautions of the break statement in PHP In PHP programming, the break statement is a control statement used to interrupt the execution of a loop or switch statement. The break statement can immediately jump out of the current loop or switch statement, allowing the program execution flow to jump directly to the code part after the loop or switch statement, thus improving the efficiency and flexibility of program execution. In actual programming, the break statement plays an important role, but it also requires attention to some details and precautions. 1.b
