1.if...else...
2.switch:
在java中,switch语句可以接收的数据类型:byte,int,short,char,枚举(1.5后),string(1.7后)
switch(变量):
case 值:
在JavaScript中,switch语句可以接收任意的原始数据类型
3.while
4.do...while
5.for
1.switch语句:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>switch语句</title>
</head>
<body>
<script>
// var a = "abc";
// var a = 1;
var a = null;
switch (a) {
case 1:
alert("number");
break;
case "abc":
alert("string");
break;
case true:
alert("boolean");
break;
case null:
alert("null");
break;
case undefined:
alert("undefined");
break;
}
</script>
</body>
</html>
2.while语句:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>while语句</title>
</head>
<body>
<script>
//1-100的和
var sum = 0
var i = 1;
while (i <= 100) {
sum += i;
i++;
}
alert(sum);
document.write(sum);
</script>
</body>
</html>
3.for语句:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>for语句</title>
</head>
<body>
<script>
var sum = 0;
for (var i = 1; i <= 100; i++) {
sum += i;
}
alert(sum);
document.write(sum);
</script>
</body>
</html>