Home  >  Article  >  Web Front-end  >  Summary of usage of break, continue and return statements in javascript_javascript skills

Summary of usage of break, continue and return statements in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:53:081293browse

Since I have been reading javascript recently, let me briefly talk about some usages of the three of them in javascript

break statement:
break statement will cause the running program to exit immediately. Included in the end Layer loop or exit a switch statement. Since it is used to exit a loop or switch statement, this form of break statement is legal only when it appears in these statements.

If the termination condition of a loop is very complex, it is much easier to use the break statement to implement some conditions than to express all the conditions with a loop expression.


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

continue statement:

The continue statement is similar to the break statement. The difference is that instead of exiting a loop, it starts a new iteration of the loop.

The continue statement can only be used in the loop body of a while statement, do/while statement, for statement, or for/in statement. Using it elsewhere will cause an error!

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]

return statement:
The return statement is used to specify the value returned by the function. The return statement can only appear within the function body, appearing anywhere else in the code will cause a syntax error! When the return statement is executed, function execution will stop even if there are other statements in the function body!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn