2. 1.
1.
if...then
if
ตั ย่ง 1
วอ า ที่
P
rogramex_if1;
U CT
ses R ;
V i : integer;
ar
B
egin
Clrs
cr;
W ('Ple s ine i = ;re d (i );
rite ae s rt ') a ln
if i>0th nW ('i mreth n1 ');
1 e rite o a 0
re d ;
a ln
E
nd.
then
ผ ลั ธ์ ไ
ล พ ทีด้
่
if...thensert i =
Ple s in
ae
_
พิ พ์ วเล น้อ ก 1 ห พิ พ์ ข1
ม ตั ข ย ว่า 0 รือ ม เล 0
ค สังที่ ยู่ ลั thenจ ทงา
า ่ อห ง
ะไม่ า น
ถ้ ใส่ตั ข า ก 10โป ก จ
า วเล ม ก ว่า
รแ รม ะ
ทงา งนี้
า นดั
im than 10
ore
2201-2410)
3. if...then Else
if
Else
then
Else
ตั ย่ง 1
วอ า ที่
ผ ลั ธ์ ไ
ล พ ทีด้
่
P
rogramex_else1;
U CT
ses R ;
Ple s ine i =
ae s rt _
V i : integer;
ar
พิ พ์ วเล ม ก 1 โป ก จ า
ม ตั ข าก ว่า 0 รแ รม ะทงาน
i m than 10_
ore
B
egin
Clrs
cr;
W ('Ple s ine i = ;re d (i ); หาก วเล น้อ ก 1 จ ราก อ วาม
rite ae s rt ') a ln
ใส่ตั ข ย ว่า 0 ะป ฎข้ ค
i lessthanor equal10
if i>0th n
1 e
W ('i mreth n1 ')
rite o a 0
Els
e
W ('i lesth no e u l 1 ');
rite s a r q a 0
re d ;
a ln
E
nd.
if...then..Else
2201-2410)
5. if
Case...of
ตั ย่ง 1
วอ า ที่
P
rogramex_if;
U CT
ses R ;
V Score : integer;
ar
B
egin
Clrs
cr;
W (' ine Yo rSco = ;re d (Sco );
rite s rt u re ') a ln re
if (Sco > 8 )a d (Sco < 1 0 th n
re =0 n
re = 0 ) e
W ('Yo rGra eisA');
rite u d
if (Sco > 7 )a d (Sco <0 th n
re =0 n
re 8 ) e
W ('Yo rGra eisB');
rite u d
if (Sco > 6 )a d (Sco <0 th n
re =0 n
re 7 ) e
W ('Yo rGra eisC');
rite u d
if (Sco > 5 )a d (Sco <0 th n
re =0 n
re 6 ) e
W ('Yo rGra eisD ;
rite u d ')
if (Sco > 0)a d (Sco <0 th n
re = n
re 5 ) e
W ('Yo rGra eisF');
rite u d
if (Sco > 0)a d (Sco >0 ) th n
re = n
re 1 0 e
W ('Yo rs reisin rre ;
rite u co co ct')
re d ;
a ln
E
nd.
A , B , C, D
ผ ลั ธ์ ไ
ล พ ทีด้
่
F
ine Yo rSco =
s rt u re _
ค นนม ก
ะแ าก ว่าหรือ ากั 80แ ไม่ น100
เท่ บ ต่ เกิ
ได้ รดA
เก
ค นนม ก
ะแ าก ว่าหรือ ากั 70แ น้อ ก 80
เท่ บ ต่ ย ว่า
ได้ รดB
เก
ค นนม ก
ะแ าก ว่าหรือ ากั 60แ น้อ ก 70
เท่ บ ต่ ย ว่า
ได้ รดC
เก
ค นนม ก
ะแ าก ว่าหรือ ากั 50แ น้อ ก 60
เท่ บ ต่ ย ว่า
ได้ รดD
เก
ค นนม ก
ะแ าก ว่าหรือ ากั 0แ น้อ ก 50
เท่ บ ต่ ย ว่า
ได้ รดF
เก
2201-2410)
7. Repeat Until
ตั ย่ง1
วอ า
P
rogramexloop1;
U CT
ses R ;
V k: B
ar yte
B
egin
Clrs
cr;
k:= ;
0
re e t
pa
k:= 1
k+;
W ('T isloop', k);
rite his
until k=5;
readln;
E
nd.
ผ ลั ธ์ ไ
ล พ ทีด้
่
T isislo p
h o1
T isislo p
h o2
T isloop3
his
T isloop4
his
T isloop5
his
2201-2410)