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:03]
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 26: Line 32:
 </​sxh>​ | </​sxh>​ |
  
-\\ +จากตารางข้างบน เป็นรูปแบบ Loop ที่มี statement แค่บรรทัดเดียวต่อหนึ่ง condition เท่านั้น อย่างไรก็ตามหากมี statement หลายบรรทัด ต้องเติม begin .. end ด้วยทุกครั้ง ​__**ยกเว้น**__ Repeat..Until Loop ดังนี้
- +
-จากตารางข้างบน เป็นรูปแบบ Loop ที่มี statement แค่บรรทัดเดียวต่อหนึ่ง condition เท่านั้น อย่างไรก็ตามหากมี statement หลายบรรทัด ต้องเติม begin .. end ด้วยทุกครั้ง ดังนี้+
  
 <hidden Loops: Multiple Statements>​ <hidden Loops: Multiple Statements>​
Line 51: Line 55:
     {Statement1};​     {Statement1};​
     {Statement2};​     {Statement2};​
 +    ...
   end;   end;
 </​sxh>​ |<sxh delphi;> </​sxh>​ |<sxh delphi;>
 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;>
-Repeat {Statement} until +Repeat ​ 
 +  ​{Statement1}
 +  {Statement2};​  
 +  ...  
 +until 
   {Condition};​   {Condition};​
 </​sxh>​ |<sxh delphi;> </​sxh>​ |<sxh delphi;>
 i:=0; i:=0;
-Repeat i:=i+1 until +Repeat ​ 
 +  ​i:=i+1
 +  writeln('​i = ',​i){;​} 
 +until 
   i<10;   i<10;
 </​sxh>​ | </​sxh>​ |
 +</​hidden>​
 +
 +__**หมายเหตุ**__ - คำสั่งสุดท้ายของ Repeat ก่อนจะเข้าสู่ Until จะใส่เครื่องหมาย ";"​ ปิดท้ายหรือไม่ก็ได้
  
 \\ \\
tutorial/loopstatement.1546848205.txt.gz · Last modified: 2019/01/07 15:03 by admin