JS 21 break continue

break can be used in switch and loop statements;
break immediately terminates the loop closest to it; in nested loops, it can only terminate one layer closest to it
// can be used in the if in the for loop, not alone Use; in if.

continue is used in the loop body
// it can be used in the switch in the for loop, and cannot be used in the switch alone;
continue skips the current loop; continue only works on the nearest loop;

There is a difference between break and continue when used in a switch statement within a loop .
break means to jump out of this switch, and the code behind the switch continues to execute, and
continue means not to execute the code after the switch, which can be understood as jumping out of the current loop and then entering the next loop.
insert image description here

insert image description here
insert image description here
insert image description here
Terminate the inner and outer layers: (continue is the same as break)
insert image description here

Guess you like

Origin blog.csdn.net/weixin_40929263/article/details/108002285