Javascript flow control - break and countinue

1. break statement

1. The break statement is used to jump out of the loop

2. The loop body where break is located has ended

3, after the break statement will not be executed

	<script type="text/javascript">
 		var num = 0;
 		while(true) {
 			console.log(num);
 			if(10 === num) {
 // Break 				out of the loop when num====10
 				;
 				alert("Will it be executed?");
 			}
 			num++;
 		}
 	</script>

2. The countinue statement

1. If a specific condition occurs during the loop, skip the current one, and then continue the loop iteration;

2. The loop body does not end, but is interrupted under certain conditions in the loop

	<script type="text/javascript">
		// find odd numbers between 0-10
		var num=0;
		while (num<10){
			num++;
			if(num%2===0){
				continue;//End this loop and enter the next loop
			}
			console.log(num);
		}
	</script>






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325642178&siteId=291194637