Js-break: The breakstatement 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
1 for(vari=1;i<=10;i++) { 2 if(i==8) { 3 Break; 4 } 5 Console.log (i);6 }7 //when i=8, exit for this loop directly. This loop will no longer be executed! Output Result: 12345678 varN=1;9 varn=2;Ten varN=3; One Switch(n) { A Case1: -Console.log (1) - Break; the Case2: -Console.log (2) - Break; - default: +Console.log (' Other ') -}
js-continue: The continue statement is similar to the break statement. The difference is that instead of quitting 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, and will cause an error in other places!
1 for ( var i=1;i<=10;i++) { 2 if (I==8 3 continue ; 4 } 5 Console.log (i); 6 } 7 // when i=8, just jump out of the for loop. Continue the execution next time. Output result: 1234567910
Js-return: 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!
1 varFun =function () {2 for(vari=0; i<5; i++){3 if(i==2){4 return 5 }6 Console.log (i)7 }8 }9 TenFun ();//Output 0 1
Javascript-about break, continue, return statement