Javascript: 14 JavaScript break and continue

Source: Internet
Author: User
Document directory
  • Break
  • Instance:
  • Result:
  • Continue
  • Instance:
  • Result:

There are two statements that can be used in a loop: Break and continue.

Instance
Break statement
Use the break statement to terminate the loop.
Continue statement
Use the continue statement to terminate the current loop and continue execution from the next value.
Javascript break and continue statements

There are two special statements available in the loop: Break and continue.

Break

The break command can terminate the running of the loop and then continue executing the code after the loop (if there is code after the loop ).

Instance:
{break}document.write("The number is " + i)document.write("<br />")}</script></body>Result:
The number is 0The number is 1The number is 2
Continue

The continue command terminates the current loop and continues running from the next value.

Instance:
{continue}document.write("The number is " + i)document.write("<br />")}</script></body>Result:
The number is 0The number is 1The number is 2The number is 4The number is 5The number is 6The number is 7The number is 8The number is 9The number is 10

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.