JavaScript Break and Continue statements

breakstatement is used to break out of the loop.

continueUsed to skip an iteration in the loop.


Break Statement

We have already seen the break statement in the previous chapters of this tutorial. It is used to break out of switch() statements.

The break statement can be used to break out of a loop.

After the break statement breaks out of the loop, the code after the loop will continue to be executed (if any):

Example

    php中文网(php.cn) 

点击按钮,测试带有 break 语句的循环。

Run the program and try it


Continue statement

continue statement interrupts the iteration in the loop if the specified condition occurs , and then continue with the next iteration in the loop. This example skips value 3:

    php中文网(php.cn) 

点击下面的按钮来执行循环,该循环会跳过 i=3 的步进。

Run the program to try it


JavaScript tag

As you As you saw in the chapter on switch statements, JavaScript statements can be marked.

To label a JavaScript statement, add a colon before the statement:

label:
statements

The break and continue statements are just Statements that can jump out of code blocks.

Syntax:

break labelname;

continue labelname;

The continue statement (with or without label reference) can only be used within a loop.

break statement (without label reference), can only be used in a loop or switch.

Referenced through tags, the break statement can be used to break out of any JavaScript code block:

Example

    php中文网(php.cn) 

Run the program to try it out



Continuing Learning
||
php中文网(php.cn)

点击按钮,测试带有 break 语句的循环。

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!