记录一些js基础语法的总结第二篇——流程控制
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jsStudy</title>
</head>
<body>
<script>
//1.if-else if-else选择
let num = 1
if (num == 1) {
console.log('yes')
} else if (num == 0) {
console.log('no')
} else {
console.log('error')
}
//2.switch选择 break退出循环
switch (num) {
case 1://常量值/变量/表达式
console.log('yes')
break;//一定要break,否则会穿透
case 0:
console.log('no')
break;
default:
console.log('error')
}
//3.while循环
let array = [0, 1]
let i = 0
while (i < array.length) {
console.log(array[i])
i++
}
//4.for循环 continue跳过一次循环
for (let index = 0; index < array.length; index++) {
console.log(array[index])
if (index == 1) {
continue
}
}
//5.for in循环遍历对象
var obj = {
name: 'cxk',
hobby: '唱,跳,rap,篮球'
};
for (let key in obj) {
console.log(obj[key])
}
</script>
</body>
</html>
标签:index,console,log,JavaScript,基础,num,let,array
From: https://blog.csdn.net/qq_58432692/article/details/141363951