1.if
if(条件){ }else{ }
2.do-while
do{ }while(条件)
3.while
while(条件){ }
4.for
for(var i=0;i<7;i++){ statement }
5.for-in
for(property in expression){ statement }
6.label
label: statement 下面是一个示例: start: for (var i=0; i < count; i++) { alert(i); }
7.break 退出循环 continue退出当前循环
8.with
with (expression) statement;
定义 with 语句的目的主要是为了简化多次编写同一个对象的工作,如下面的例子所示:
var qs = location.search.substring(1);
var hostName = location.hostname;
var url = location.href;
上面几行代码都包含 location 对象。如果使用 with 语句,可以把上面的代码改写成如下所示:
with(location){ var qs = search.substring(1); var hostName = hostname; var url = href; }
9.switch
switch (expression) { case value: statement break; case value: statement break; case value: statement break; case value: statement break; default: statement }