5.条件语句
if ,if else
if( 1 > 2) {
document.write('a');
}
switch case
let n = parseInt(window.prompt('input'));
switch(n) {
case 'a':
console.log('a');
break;
case 'b':
console.log('b');
break;
case 'c':
console.log('c');
}
条件语句中的continue 和 break
for(var a = 0; a < 100; a++) {
if(a % 7 === 0 || a % 10 === 7) {
continue;
}
console.log(a);
}
let date = parseInt(window.prompt("input"));
switch(date) {
case "monday":
case "tuesday":
case "wednesday":
case "thursday":
case "friday":
console.log("工作日");
break;
case "monday":
case "sunday":
console.log("休息日");
}
2.循环语句
①for循环
for(var a = 0; a < 10; a++) {
document.write(a)
}
var a = 0;
for(;a < 10;) {
document.write(a);
a++;
}
②while循环
var a = 0;
while(a < 10) {
document.write(a);
a++;
}
do{} while() 循环
do {
document.write(a);
a++;
} while (a < 10);