
Program 程序首部;
单元引用; ∥ 声明部分
常量声明;
类型定义;
变量声明;
过程和函数声明;
Begin ∥程序体
语句体;
End
语句与语句之间用分号隔开
程序最后以(.)结束。
Program 表示一个程序的开始
Var表示变量说明部分
Integer 整数类型
Real 实数类型
Boolean 布尔类型
Char 字符类型
Const 常量标识字符=常量
输入语句 readln(length,width)
输出语句 writeln(‘Area is ‘,…..” )
赋值运算符 (:=)
赋值语句中的“:=”应看作一个完整的符号,为赋值号。
如:S:=a+b; x:=15;
类型定义:type
如:Type colour=(while,red,blue);
1. IF语句
格式:if布尔表达式 then 语句 else 语句
例:if x>=0
then y:=x
else y:=-x
2.case 语句
格式:case情况表达式 of
情况常量表 :语句;
-┄┄
情况常量表 :语句;
End .
例 求某月的天数
case month of
jan,mar,may,jul,aug,oct,dec;
len:=31;
apr,jun,sep,nov;
len:=30;
feb:
if (year mod 4=0 ) and (year mod 100 <> 0 )
then len:=29
then len:=28
end.
例:求1~100的和
Program sum100 for;
var i,s:integer ;
begin
s:=0;
for i:=1 to 100 do
s:=s+i;
writeln(‘s=’,s);
readln;
end
