웹 개발 코드 : 휴식 : 루프에서, 배열의 요소를 통과 할 문에 들어 ... 사용, 스킵 루프 반복 계속

1, 휴식 : 루프에서

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>now test</title> 

</head>
<body>
		<p>点击下面的按钮,测试带有break语句的循环</p>
		<button onclick="myFunction()">点我点我</button>
		<p id="demo"></p>
<script>
function myFunction(){
	var x="",i=0;
	for (i=0;i<10;i++){
		if(i==3){
			break;
		}
		x=x+"该数字为"+i+"<br>";
	}
	document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html> 

2, 건너 뛰는 반복 루프 계속

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>now test</title> 

</head>
<body>
		<p>点击下面的按钮,测试带有break语句的循环</p>
		<button onclick="myFunction()">点我点我</button>
		<p id="demo"></p>
<script>
function myFunction(){
	var x="",i=0;
	for (i=0;i<10;i++){
		if(i==3){
			continue;
		}
		x=x+"该数字为"+i+"<br>";
	}
	document.getElementById("demo").innerHTML=x;
}
</script>
</body>
</html> 

3, 성명 들어 ...를 사용하여 배열의 요소를 통과 할

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>now test</title> 

</head>
<body>
		<p>点击下面的按钮,循环遍历对象“person”的属性</p>
		<button onclick="myFunction()">点我点我</button>
		<p id="demo"></p>
<script>
function myFunction(){
	var x;
	var txt="";
	var person={fname:"Billtui",lname:"Galltes",age:56};
	for (x in person){
		txt=txt +person[x];
	}
	document.getElementById("demo").innerHTML=txt;
}
</script>
</body>
</html> 

추천

출처blog.csdn.net/weixin_43731793/article/details/93978526