分支与循环

54 阅读1分钟

分支结构

if

if

image.png

if else

image.png

if else if

image.png

swich

switch 和 case 都允许任意表达式。

let a = "1";
let b = 0;
switch (+a) 
{
case b + 1:
alert("this runs, because +a is 1, exactly equals b+1");
break;
default:
alert("this doesn't run");
}

image.png

循环结构

while

在 while 中的循环条件会被计算,计算结果会被转化为布尔值。 image.png

do while

image.png

for

image.png

循环控制语句

break

image.png

continue

image.png