| Statements | Syntax |
|---|---|
| If..Then |
if {Condition} then {Statement};
|
| If..Then..Else |
if {Condition} then
{Statement1}
else
{Statement2};
|
| If..Then/ Else If..Then/ Else |
if {Condition1} then
{Statement1}
else if {Condition2} then
{Statement2}
else
{Statement3};
|
จากตารางข้างบน เป็นรูปแบบ If ที่มี statement แค่บรรทัดเดียวต่อหนึ่ง condition เท่านั้น อย่างไรก็ตามหากมี statement หลายบรรทัด ต้องเติม begin .. end ด้วยทุกครั้ง ดังนี้
| Statements | Syntax |
|---|---|
| Exact value |
//---Single Statement---
case {Var} of
1: {Statement1};
2: {Statement2};
3: {Statement3};
else {Statement4};
end;
|
| Range |
case {Var} of
1..10: {Statement1};
11..20: {Statement2};
21..30: {Statement3};
else {Statement4};
end;
|
จากตารางข้างบน เป็นรูปแบบ Case ที่มี statement แค่บรรทัดเดียวต่อหนึ่ง condition เท่านั้น อย่างไรก็ตามหากมี statement หลายบรรทัด ต้องเติม begin .. end ด้วยทุกครั้ง ดังนี้
คำสั่ง Break, Continue, Exit และ Goto สรุปได้ดังนี้
| Procedures | Meaning | Format |
|---|---|---|
| Break | ออกจาก Loop ปัจจุบัน (For/While/Repeat) |
for i:=1 to 10 do
if i=5 then break;
writeln('i = ',i); //i = 5
readln;
|
| Continue | สิ้นสุด Loop ปัจจุบันทันที เพื่อเริ่ม Loop ปัจจุบันใหม่ในรอบถัดไป (For/While/Repeat) |
for i:=1 to 5 do
begin
if i=4 then continue;
writeln('i = ',i); //i = 4 won't be showed
end;
|
| Exit | ออกจาก Sub-Program ปัจจุบัน (Procedure/Function) |
procedure MyProc;
begin
exit;
writeln('After Exit'); //This won't be shown
end;
|
| Goto | ไปยัง Label ที่ระบุ |
label PointA,PointB; //declare labels
BEGIN
Goto PointB;
PointA:
wrtieln('Passing PointA');
exit; //Exit the program
PointB:
wrtieln('Passing PointB');
Goto PointA;
END.
|