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 14:59]
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 ดังนี้
 +
 +<hidden Loops: Multiple Statements>​
 +^  Statements ​ ^  Syntax ​ ^  Example ​ ^ 
 +|For..Do|<​sxh delphi;>
 +For i:={Start} to {End} do
 +  begin
 +    {Statement1}; ​
 +    {Statement2};​
 +    ...
 +  end;
 +</​sxh>​ |<sxh delphi;>
 +For i:=1 to 10 do
 +  begin
 +    j:=i*2+5;
 +    writeln('​i = ',​i); ​
 +  end;
 +</​sxh>​ |
 +|While..Do|<​sxh delphi;>
 +While {Condition} do 
 +  begin
 +    {Statement1};​
 +    {Statement2};​
 +    ...
 +  end;
 +</​sxh>​ |<sxh delphi;>
 +i:=0
 +While i<10 do 
 +  begin
 +    writeln('​i = ',i);
 +    i:=i+1;
 +  end;
 +</​sxh>​ |
 +|Repeat..Until|<​sxh delphi;>
 +Repeat ​
 +  {Statement1};​
 +  {Statement2}; ​
 +  ... 
 +until 
 +  {Condition};​
 +</​sxh>​ |<sxh delphi;>
 +i:=0;
 +Repeat ​
 +  i:=i+1;
 +  writeln('​i = ',​i){;​}
 +until 
 +  i<10;
 +</​sxh>​ |
 +</​hidden>​
 +
 +__**หมายเหตุ**__ - คำสั่งสุดท้ายของ Repeat ก่อนจะเข้าสู่ Until จะใส่เครื่องหมาย ";"​ ปิดท้ายหรือไม่ก็ได้
 +
 +\\
tutorial/loopstatement.1546847976.txt.gz · Last modified: 2019/01/07 14:59 by admin