DelphiBasics
Do
Keyword
Defines the start of some controlled action
 keyword Do(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 Statements section of the control action.
Related commands
BeginKeyword that starts a statement block
EndKeyword that terminates statement blocks
ExceptStarts the error trapping clause of a Try statement
ForStarts a loop that executes a finite number of times
RepeatRepeat statements until a ternmination condition is met
TryStarts code that has error trapping
WhileRepeat statements whilst a continuation condition is met
WithA means of simplifying references to structured variables
 Download this web site as a Windows program.




 
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
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page