Web開発コード:ブレーク:ループの外に、スキップループ反復継続については、使用して...声明の中で配列の要素を横断します

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