Mega Code Archive

 
Categories / Delphi / Keywords
 

Do - defines the start of some controlled action

1. for Variable := Expression to Expression do Statement; 2. while Expression do Statement 3. try Statements except on ExceptionClass do Statement; end; 4. with Expression do Statement Description The Do keyword is always a part of one of the shown 4 control types. It precedes the Sattements section of the control action. Related commands Begin Keyword that starts a statement block End Keyword that terminates statement blocks Except Starts the error trapping clause of a Try statement For Starts a loop that executes a finite number of times Repeat Repeat statements until a ternmination condition is met Try Starts code that has error trapping While Repeat statements whilst a continuation condition is met With A means of simplifying references to structured variables Example code : Show singles and block do statement blocks var i : Integer; begin // A for statement - the do keyword precedes a single statement for i := 1 to 3 Do ShowMessage('For loop, i = '+IntToStr(i)); // A while statement - the do precedes a statement block while i < 6 Do begin ShowMessage('While loop, i = '+IntToStr(i)); Inc(i); end; end; Show full unit code For loop, i = 1 For loop, i = 2 For loop, i = 3 While loop, i = 4 While loop, i = 5