一、常量声明语句
常量用“=”表示两边的值是相等的。
const
Pi = 3.14159;
Answer = 342;
ProductName = 'Delphi';
二、赋值语句 :=
3:goto
4:复合语句: 类似于{}
begin
..
end
5: if 语句(后面跟then , else ) (python后跟冒号,C++(java)跟{})
举例来说
if J <> 0 then
begin
Result := I/J;
Count := Count + 1;
end
else if Count = Last then
Done := True
else
Exit;
六、case语句:
case语句用来在多个可能的情况下选择一个条件。例如
case MyColor of
Red: X := 1;
Green: X := 2;
Blue: X := 3;
Yellow, Orange, Black: X := 0;
end;
case Selection of
Done: Form1.Close;
Compute: CalculateTotal(UnitCost, Quantity);
else
Beep;
end;
七、repeat语句(类似于C++中的do...while())
repeat语句重复执行一行或一段语句直到某一状态为真。例如
- repeat
- K := I mod J;
- I := J;
- J := K;
- until J = 0;
- repeat
- Write('Enter a value (0..9): ');
- Readln(I);
- until (I >= 0) and (I <= 9);
八、while语句.(循环开始前接口do,for语句一样)
while语句与repeat语句的不同之处在于while语句在循环的开始阶段就进行判断,也就不存在多执行一次循环语句的情况了。
while Data[I] <> X do I := I + 1;
while I > 0 do
begin
if Odd(I) then Z := Z * X;
I := I div 2;
X := Sqr(X);
end;
while not Eof(InputFile) do
begin
Readln(InputFile, Line);
Process(Line);
end;
九、for语句
for语句需要明确指定想要的循环来遍历的迭代次数:
for I:=2 to 63 do
if Data[i]>....
end
十、Break过程Continue()过程
十二、with()语句
在使用记录类型的时候,使用with语句来针对某一个变量说明。with语句的结构为
with obj do statement or with obj1,obj2,...,objn do statement
with语句的例子
with OrderDate do
if Month = 12 then
begin
Month := 1;
Year := Year + 1;
end
else
Month := Month + 1;