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

WBOY
Release: 2016-05-16 17:53:10
Original
1069 people have browsed it

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
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template