流程控制:
赋值语句: var varible=30;
var varible="学习Javascript”;
var varible=false;
if语句: if(expression){
statement1
}else{
statement2
}
if语句嵌套: var m=12,n=m;
if(m<1){
if(n==1)
alert("判断m小于1,n等于1");
else
alert("判断m小于1,n不等于1");
}else if(m>10){
if(n==1)
alert("判断m大于10,n等于1");
else
alert("判断m大于10,n不等于1");
}
Switch语句:多路分支语句
switch(expression){
case judgment 1:
statement 1;
break;
case judgment 2:
statement 2;
break;
...
case judgement n:
statement n;
break;
default:
statement n+1;
break;循环控制语句:while语句、do...while语句、for循环
while语句: while(expression){
statement
}
do...while语句: do{
statement
} while(expression);
for循环: for(initialize;test;incresment){
statement
}
跳转语句:
continue语句:var total=0;
var sum=new Array(1000,1200,100,600,736,1107,1205);
for(i=0;i<sum.length;i++){
if(sum[i]<1000)continue;
total+=sum[i];
}
document.write("累加和为:"+total);
break语句: var sum=0;
for(i=0;i<100;i++){
sum+=i
if(sum>10) break;
}
document.write("0至"+i+"(包括"+i+")之间自然数的累加和为:“+sum);