User Tools

Site Tools


tutorial:conditionalstatement

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:conditionalstatement [2019/01/07 09:48]
admin [Case - Statements]
tutorial:conditionalstatement [2019/01/07 13:00] (current)
admin [Break, Continue, Exit and Goto]
Line 93: Line 93:
  
 </​sxh>​ | </​sxh>​ |
-\\ 
  
 จากตารางข้างบน เป็นรูปแบบ Case ที่มี statement แค่บรรทัดเดียวต่อหนึ่ง condition เท่านั้น อย่างไรก็ตามหากมี statement หลายบรรทัด ต้องเติม begin .. end ด้วยทุกครั้ง ดังนี้ จากตารางข้างบน เป็นรูปแบบ Case ที่มี statement แค่บรรทัดเดียวต่อหนึ่ง condition เท่านั้น อย่างไรก็ตามหากมี statement หลายบรรทัด ต้องเติม begin .. end ด้วยทุกครั้ง ดังนี้
Line 143: Line 142:
 </​sxh>​ | </​sxh>​ |
 </​hidden>​ \\ </​hidden>​ \\
-===== Break, Continue and Goto =====+===== Break, Continue, Exit and Goto ===== 
 +คำสั่ง Break, Continue, Exit และ Goto สรุปได้ดังนี้  
 + 
 +^  Procedures ​ ^  Meaning ​ ^  Format ​ ^ 
 +| Break | ออกจาก Loop ปัจจุบัน (For/​While/​Repeat) |<sxh delphi;>​ 
 +  for i:=1 to 10 do 
 +    if i=5 then break; 
 + 
 +  writeln('​i = ',​i); ​ //i = 5 
 +  readln;  
 +</​sxh>​ | 
 +|Continue| สิ้นสุด Loop ปัจจุบันทันที เพื่อเริ่ม Loop ปัจจุบันใหม่ในรอบถัดไป (For/​While/​Repeat) |<sxh delphi;>​ 
 +  for i:=1 to 5 do 
 +  begin 
 +    if i=4 then continue; 
 +    writeln('​i = ',i); //i = 4 won't be showed 
 +  end;  
 +</​sxh>​ | 
 +|Exit| ออกจาก Sub-Program ปัจจุบัน (Procedure/​Function) |<sxh delphi;>​ 
 +procedure MyProc; 
 +begin 
 +  exit; 
 +  writeln('​After Exit'​);​ //This won't be shown 
 +end; 
 +</​sxh>​ | 
 +|Goto| ไปยัง Label ที่ระบุ |<sxh delphi;>​ 
 +label PointA,​PointB;​ //declare labels 
 +BEGIN 
 + Goto PointB; 
 + ​PointA:​ 
 + ​wrtieln('​Passing PointA'​);​ 
 + exit; //Exit the program 
 + ​PointB:​ 
 + ​wrtieln('​Passing PointB'​);​ 
 + Goto PointA; 
 +END. 
 +</​sxh>​ |
tutorial/conditionalstatement.1546829319.txt.gz · Last modified: 2019/01/07 09:48 by admin