流程控制
- Return语句
- If语句
- While循环语句
- For循环语句
- Break语句
- Continue语句
Return语句
if(true) {
10
}
if(true) {
return 10
}
If语句
if(true) {
10
}
if(true) {
10
} else {
20
}
if(1 < 3){
10.01
} elif(2 < 2){
11.11
} elif(3 < 3){
33.33
} else {
return 20.02
}
While循环与Continue、Break语句
let i = 0;
while(i < 10){
if(i == 2){
i = i + 1;
continue;
}
i = i + 1;
if(i == 4){
break;
}
print(i);
};
For循环与Continue、Break语句
let i = 1;
print("before for-loop:", i)
for(let i=0 ;i < 10; i = i + 1; ){
if(i == 3){
break;
};
print("in for-loop:", i)
};
print("after for-loop:", i)
let i = 1;
print("before for-loop:", i)
for(;i < 10; i = i + 1; ){
if(i == 3){
break;
};
print("in for-loop:", i)
};
print("after for-loop:", i)