# How JavaScript jumps out of multiple cycle break, continue_javascript skills

Source: Internet
Author: User

Let's talk about the difference between break and continue.

for (Var i=0;i<10;i++) {
if (i>5) {break
;
}
}
Console.log (i);  ---6

• When i=5 and 10 are executed to the break and exit the loop

for (Var i=1;i<10;i++) {
if (i>5) {
continue
}
num++;
}
Console.log (num);  ---4

var num=0;
for (Var i=1;i<10;i++) {
if (i%5==0) {
continue
}
num++;
}
Console.log (num); ---8

• When i=5 or i=10, follow the value of I, continue with the For loop, and exit the loop

When multiple loops are executed

The condition of the break

Outer: For
(var i=0;i<10;i++) {
Inter: for
(var j=0;j<10;j++) {
if (i>5)
{ Console.log (i); ----6 Break
outer}
}

This is the break to the outermost loop inside

Outer: For
(var i=0;i<10;i++) {
Inter: for
(var j=0;j<10;j++) {
if (i>5) {
Console.log (i) ; ----6,7,8,9 break
inter;
}
}

This is a break to the inner surface of the time, although not jump out for the moment, but 4 times after execution, or jumped out

The situation of continue

var num=0;
Outer: For
(var i=0;i<10;i++) {
Inter: for
(var j=0;j<10;j++) {
if (i>5)
{ Console.log (i); ----6,7,8,9
continue outer;
}
num++
}
}
Console.log (num);     ---60

Whenever I is greater than or equal to 5 will pop up to continue the cycle, so, will be less than 40 times.

var num=0;
Outer: For
(var i=0;i<10;i++) {
Inter: for
(var j=0;j<10;j++) {
if (i>5)
{ Console.log (i); ----6,7,8,9
continue inter;
}
num++
}
}
Console.log (num);     ---60

The same principle, the loop will continue to execute, but only less 40 times, because the limit is always the value of I, I is less than or equal to 5 will not be set up.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.