JS in the end of the three keyword break,continue,return__ function

Source: Internet
Author: User

* * logic Control as the core of JS programming, in the coding is most commonly used, then in the process of using some common problems need to use a specific statement to achieve.

We use more is the circular statement, in the circular statement, there must be meet the conditions or do not meet the conditions to jump out of the cycle of the moment, this time to use the circular concluding sentence, is usually used to break out of the current whole cycle; If you jump out of a loop and continue when you meet the At this point, the available Continue;return function is generally used to end the function. break means to jump out of the entire loop, which is the end. Most commonly used in switch control statements, as follows:

Switch (property) {case
    1:
    function () {};
    break;
    Case 2:
    function () {};
    break;
    ...
    ...
    ...
    Default:
    function () {};
}

The loop statement represents the value of the judgement property, satisfies any kind of case, executes the corresponding function, and then exits the fragment. continue means to jump out of this loop and generally use it in a for loop. As follows:

for (int i=0;i<5;i++) {
    if (i==2)
    continue;
    var a=i;
    Console.log (a);

}

This function, when i=2, does not execute the following output statement, but continues executing the output statement when i!=2. If continue is replaced with a break, the output statement is not executed after 2 and 2. Return is generally used in functions to block the execution and termination functions of the default function. You can use return False if you block bubbling; To achieve. The End function is shown as follows:

Function Show () {
    var a=2;
    return A;
    var b=0;
    return b;
}

The execution of this code results in 2. In other words, when execution to return a; , the show function ends, does not execute the following statements, and does not overwrite the returned value.

Contact Us

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.