; age:=23;
sex:='male';
end;
(4)goto 语句
现在所有声音都是说要减少goto语句是使用,所以尽量少用为是。
示例:
label mylabel; //用label保留字声明mylabel
mylabel: //标记
、、、 //其它语句
goto mylabel; //跳转到mylabel 处
(5)条件语句
a、if ... then ... 语句
if 布尔表达式 then ..;
或 if 布尔表达式 then
begin
...
end;
其它格式:
if ... then... else ...;
if ... then .. else if ... then ... else ...;
b、case ... of 语句
case 表达式 of
值1:...
值2:...
...
值n:...
end;
6)循环语句
a、for ... to ... do 语句
for 循环变量:=初值 to 终值 do ...;
或 for 循环变量:=初值 to 终值 do
begin
。。。
end;
b、while ... do 语句
while 布尔表达式 do ...;
或 while 布尔表达式 do
begin
...
end;
c、repeat ... until 语句
repeat ... until 布尔表达式;
(7)循环的中断
break: 循环结束
continue:结束本次循环
goto:(略)
exit:退出当前函数或过程
halt():终止整个程序,参数为整数
runerror():(略)
三、过程与函数
(1) 过程(无返回值)
声明: procedure <过程名> (<参数列表>);
(2)函数(有返回值)
声明: function <函数名> (<参数列表>):返回值类型;
用result 或 <函数名>返回函数值;
即在函数中用 result:=函数值;或 <函数名>:=函数值;返回;