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
Last revision Both sides next revision
tutorial:conditionalstatement [2019/01/07 10:08]
admin [Break, Continue and Goto]
tutorial:conditionalstatement [2019/01/07 12:56]
admin [Break, Continue, Exit and Goto]
Line 146: Line 146:
  
 ^  Procedures ​ ^  Meaning ​ ^  Format ​ ^ ^  Procedures ​ ^  Meaning ​ ^  Format ​ ^
-| Break | ออกจาก Loop ปัจจุบัน |<sxh delphi;>​ +| Break | ออกจาก Loop ปัจจุบัน ​(For/​While/​Repeat) ​|<sxh delphi;>​ 
-procedure ProcedureName+  for i:=1 to 10 do 
-begin +    if i=5 then break
-  ​{Do something} + 
-end;+  ​writeln('​i = ',​i); ​ //i = 5 
 +  ​readln
 </​sxh>​ | </​sxh>​ |
-|Continue| สิ้นสุด Loop ปัจจุบัน เพื่อไปข้า ​Loop ถัดไป |<sxh delphi;>​ +|Continue| สิ้นสุด Loop ปัจจุบันทันที ​เพื่อเริ่ม ​Loop ปัจจุบันใหม่ในรอบถัดไป ​(For/​While/​Repeat) ​|<sxh delphi;>​ 
-procedure ProcedureName;​ +  for i:=1 to 5 do 
-begin +  begin 
-  {Do something} +    if i=4 then continue; 
-end;+    ​writeln('​i = ',i); //i = 4 won't be showed 
 +  ​end; 
 </​sxh>​ | </​sxh>​ |
-|Exit| ออกจาก Sub-Routine ​ปัจจุบัน |<sxh delphi;>​ +|Exit| ออกจาก Sub-Program ​ปัจจุบัน ​(Procedure/​Function) ​|<sxh delphi;>​ 
-procedure ​ProcedureName;+procedure ​MyProc;
 begin begin
-  ​{Do something}+  ​exit; 
 +  writeln('​After Exit'​);​ //This one won't be shown
 end; end;
 </​sxh>​ | </​sxh>​ |
 |Goto| ไปยัง Label ที่กำหนด |<sxh delphi;> |Goto| ไปยัง Label ที่กำหนด |<sxh delphi;>
-PROGRAM Test_Goto;​ +label PointA,PointB//declare labels
-var Answer:​Char;​ +
-label RightWay,​LeftWay,WrongWay;+
 BEGIN BEGIN
-write('​Please select your way: R/​L'​);​ + ​Goto ​PointB
-readln(Answer);​ + PointA
-if Answer='​R'​ then  + wrtieln('Passing PointA'); 
-  Goto RightWay + ​exit; ​//Exit the program 
-else if Answer='​L'​ then  + PointB
-  Goto LeftWay + wrtieln('Passing PointB'); 
-else  + Goto PointA;
-  ​Goto ​WrongWay+
- +
-RighWay+
-  ​writeln('you have selected Right Way'); +
-  exit; +
-LeftWay+
-  ​writeln('you have selected Left Way'); +
-  ​exit;​ +
-WrongWay: +
-  writeln('​you have selected wrong Way'​);​ +
-  exit;+
 END. END.
 </​sxh>​ | </​sxh>​ |
tutorial/conditionalstatement.txt · Last modified: 2019/01/07 13:00 by admin