## 语句分类
![](https://box.kancloud.cn/002a6d163d4852a0d223db5d2d8b971b_746x422.png)
![](https://box.kancloud.cn/6232f717834acd33372e9b4d6bf113a3_713x484.png)
### if(){}
`if(box>100) alert("执行");`
### if(){}else{}
### if(){}else if(){}else{}
### switch语句
~~~
var box=1;
switch(box){
case 1:
alert("ok");
break;
case 2:
alert("wrong");
break;
default:
alert("出错");
}
~~~
break 退出switch语句
### do...while
~~~
var box=1;
do{
alert(box);]
box++;
}while(box<=5);
~~~
### while
### for语句
` for(var a=0;a<10;a++){ }`
### for...in...语句
处理对象时,枚举对象属性
~~~
var box={
"姓名":"田伟",
'age':1,
'height':175
}
for(var x in box){
alert(x);
}
~~~
### break和continue语句
break立即退出循环体
continue退出当前循环,执行后面的循环
~~~
for(var a=0;a<=10;a++){
if(a==5) break;
document.write(a);
}
~~~
~~~
for(var a=0;a<=10;a++){
if(a==5) continue;
document.write(a);
}
~~~
### with语句
将代码块作用域放到一个特定对象中
~~~
var box={
'name':田伟,
'age':1,
'height':175
}
with(box){ //with(box)省略掉box.
var n=name; //相当于box.name
var a=age;
var h=height;
}
alert(n);
~~~