Home Web Front-end JS Tutorial Special usage and introduction of break and continue in javascript_javascript skills

Special usage and introduction of break and continue in javascript_javascript skills

May 16, 2016 pm 05:53 PM
break continue

Today when I was studying a system, I found that its code has such a structure (simplified):

Copy the code The code is as follows:

var result = false;
point:
{
var obj = { key: 1 };
for (var key in obj) {
// .. .
break point;
}
result = true;
}
alert(result);

At first glance, I thought it was a code error, even in Visual Studio cannot format this code correctly. However, if you look closely, the semantics are still very clear, that is, break from the inside of the for loop to the specified point, and this system should not make such a mistake. Because I had never used it in this way, I conducted some tests, and the test result turned out to be that I was not good at academics. . . This is the existing syntax of JavaScript. Break can have position tags. After checking the relevant documents, we found that continue can also have position tags.

Their syntax is:

break [label];
continue [label];
We know that break in the loop body can only jump out of the current loop, and when With break labeled, you can jump to a certain position at will and easily jump out of multiple loops. In addition, break in switch can also be used in this way.

Reference documentation:

https://developer.mozilla.org/en/JavaScript/Reference/Statements/break
http:// www.jb51.net/w3school/js/pro_js_statements_break_continue.htm
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The role and use of the continue keyword in PHP The role and use of the continue keyword in PHP Jun 28, 2023 pm 08:07 PM

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.

Does continue jump out of the current loop or all loops? Does continue jump out of the current loop or all loops? Feb 02, 2023 pm 04:20 PM

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.

What is the function of break keyword in Java? What is the function of break keyword in Java? Apr 23, 2023 am 10:13 AM

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

Let's talk about not using break in PHP switch statement Let's talk about not using break in PHP switch statement Mar 20, 2023 pm 04:55 PM

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.

JS loop learning: break out of loop statements break and continue JS loop learning: break out of loop statements break and continue Aug 03, 2022 pm 07:08 PM

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!

What is the usage of break in php What is the usage of break in php Jan 31, 2023 pm 07:33 PM

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.

What is the use of break stop statement in Go language? What is the use of break stop statement in Go language? Jan 18, 2023 pm 03:46 PM

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 function and precautions of break statement in PHP The function and precautions of break statement in PHP Mar 20, 2024 pm 05:33 PM

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

See all articles