User Tools

Site Tools


tutorial:loopstatement

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial:loopstatement [2019/01/07 15:08]
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 74: Line 81:
 </​sxh>​ | </​sxh>​ |
 </​hidden>​ </​hidden>​
 +
 +__**หมายเหตุ**__ - คำสั่งสุดท้ายของ Repeat ก่อนจะเข้าสู่ Until จะใส่เครื่องหมาย ";"​ ปิดท้ายหรือไม่ก็ได้
  
 \\ \\
tutorial/loopstatement.1546848528.txt.gz · Last modified: 2019/01/07 15:08 by admin