JavaScriptBreak and Continue difference tutorial _ basic knowledge

Source: Internet
Author: User
The difference between JavaScriptBreak and Continue provides two types of statements that can be used in loops: break and continue.
JavaScript break and continue Declaration
There are two special declarations 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:

<Html> <body> <script type = "text/javascript"> var I = 0 for (I = 0; I <= 10; I ++) {if (I = 3) {break} document. write ("The number is" + I) document. write ("")} script </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Result:
The number is 0
The number is 1
The number is 2 Continue
The continue command terminates the current loop and continues running from the next value.

Instance:

<Html> <body> <script type = "text/javascript"> var I = 0 for (I = 0; I <= 10; I ++) {if (I = 3) {continue} document. write ("The number is" + I) document. write ("")} script </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]


Result:
The number is 0
The number is 1
The number is 2
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10
Related Article

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.