Object-oriented programming syntax we will encounter break, continue, return these three commonly used keywords, then about the use of these three keywords specific operation is what? What are the rules that we need to be aware of and understand when we use these three keywords? Let's start by introducing:
The break statement for JS programming syntax:
The break statement causes the running program to immediately exit the loop that is contained in the inner layer or exit a switch statement.
Since it is used to exit a loop or switch statement, this form of break statement is valid only if 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 certain conditions than to express all the conditions with a loop expression.
for (Var i=1;i<=10;i++)
{
if (i==6)
{
Break
}
document.write (i);
}
When I=6, exit for this loop directly. This loop will no longer be executed!
Output results: 12345
JS programming syntax of the CONTINUE statement:
The continue statement is similar to the break statement. What's different is that it's not quitting a loop, but starting 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, and will cause an error in other places!
for (Var i=1;i<=10;i++)
{
if (i==6) continue;
document.write (i);
}
When I=6, just jump out of this for loop. Continue the execution next time.
Output results: 1234578910
The return statement of the JS programming syntax:
The return statement is used to specify the value returned by the function. The return statement can only appear in the function body, and anywhere else in the code will cause a syntax error!
When you execute a return statement, the function execution stops even if there are other statements in the body of the function!
JS programming syntax in the break, continue, return the use of the three commonly used keywords to introduce you here, I hope you understand and learn to break, continue, return the use of the three commonly used keywords helpful.
JS in break, continue, return