- 逻辑运算符
- 条件语句
- 单行
- 多行
- 选择语句
- 循环语句
- do-loop
- repeat-until
- while
- for
- 跳出循环
- exit
- continue
逻辑运算符由于控制语句中会用到逻辑运算符,所以先讲
| 含义 | 符号 | 示例 | 逻辑结果 |
|---|---|---|---|
| 与 | and | 1 and 0 | 0 |
| 或 | or | 1 or 0 | 1 |
| 非 | not | not 1 | 0 |
| 等于 | = | 1=0 | 0 |
| 大于 | > | 1>0 | 1 |
| 小于 | < | 1<0 | 0 |
| 大于等于 | >= | 1>=0 | 1 |
| 小于等于 | <= | 1<=0 | 0 |
复杂条件语句用括号,如:(1+1=2) and (not 0),逻辑结果是1
条件语句 单行a = 1 if a = 1 then Print(a)多行
a = 1 if a = 1 Print(a) endif
a = 1 if a = 1 Print(1) elseif a = 2 Print(2) else Print(a) endif选择语句
a = 1
select a
case 1
Print(1)
endcase
case 2
Print(2)
endcase
case default
Print(a)
endcase
endselect
也可以在case语句后加冒号,如case 1:或case default:
循环语句 do-loopa = 0 do if a < 100 a = a + 1 else exit endif looprepeat-until
a = 0
repeat
a = a + 1
until a >= 100
while
a = 0
while a < 100
a = a + 1
endwhile
for
t每次加1
for t = 1 to 10
print ( t )
next t
//打印出10个数:1~10
t每次加2
for t = 1 to 10 step 2 print ( t ) next t //打印出5个数:1,3,5,7,9跳出循环
exit和C++中的break与continue类似
跳出当前循环,多层嵌套循环时,只跳出exit语句所在的那一层
continue跳过本次循环,继续执行下一次循环



