This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
tutorial:loopstatement [2019/01/07 15:07] admin |
tutorial:loopstatement [2019/01/30 09:10] (current) admin |
||
|---|---|---|---|
| Line 4: | Line 4: | ||
| |For..Do|<sxh delphi;> | |For..Do|<sxh delphi;> | ||
| For i:={Start} to {End} do | For i:={Start} to {End} do | ||
| + | {Statement}; | ||
| + | </sxh> <sxh delphi;> | ||
| + | For i:={Start} downto {End} do | ||
| {Statement}; | {Statement}; | ||
| </sxh> |<sxh delphi;> | </sxh> |<sxh delphi;> | ||
| For i:=1 to 10 do | For i:=1 to 10 do | ||
| writeln('i = ',i); | writeln('i = ',i); | ||
| - | </sxh> | | + | </sxh><sxh delphi;> |
| + | For i:=10 downto 1 do | ||
| + | writeln('i = ',i); | ||
| + | </sxh>| | ||
| |While..Do|<sxh delphi;> | |While..Do|<sxh delphi;> | ||
| While {Condition} do | While {Condition} do | ||
| Line 25: | Line 31: | ||
| i<10; | i<10; | ||
| </sxh> | | </sxh> | | ||
| - | |||
| - | \\ | ||
| จากตารางข้างบน เป็นรูปแบบ Loop ที่มี statement แค่บรรทัดเดียวต่อหนึ่ง condition เท่านั้น อย่างไรก็ตามหากมี statement หลายบรรทัด ต้องเติม begin .. end ด้วยทุกครั้ง __**ยกเว้น**__ Repeat..Until Loop ดังนี้ | จากตารางข้างบน เป็นรูปแบบ Loop ที่มี statement แค่บรรทัดเดียวต่อหนึ่ง condition เท่านั้น อย่างไรก็ตามหากมี statement หลายบรรทัด ต้องเติม begin .. end ด้วยทุกครั้ง __**ยกเว้น**__ Repeat..Until Loop ดังนี้ | ||
| Line 56: | Line 60: | ||
| i:=0 | i:=0 | ||
| While i<10 do | While i<10 do | ||
| - | i:=i+1; | + | begin |
| + | writeln('i = ',i); | ||
| + | i:=i+1; | ||
| + | end; | ||
| </sxh> | | </sxh> | | ||
| |Repeat..Until|<sxh delphi;> | |Repeat..Until|<sxh delphi;> | ||
| Line 69: | Line 76: | ||
| Repeat | Repeat | ||
| i:=i+1; | i:=i+1; | ||
| - | writeln('i = ',i){;} //use ; in the last row is option | + | writeln('i = ',i){;} |
| until | until | ||
| i<10; | i<10; | ||
| </sxh> | | </sxh> | | ||
| </hidden> | </hidden> | ||
| + | |||
| + | __**หมายเหตุ**__ - คำสั่งสุดท้ายของ Repeat ก่อนจะเข้าสู่ Until จะใส่เครื่องหมาย ";" ปิดท้ายหรือไม่ก็ได้ | ||
| \\ | \\ | ||