This lesson we learn about for.. next loop in delphi.
A for statement requires you to specify explicitly the number of iterations you want the loop to go through.
The syntax of a for statement is :
for counter := initialValue to finalValue do statement
or
for counter := initialValue downto finalValue do statement
where counter is a local variable (declared in the block containing the for statement) of ordinal type, without any qualifiers. initialValue and finalValue are expressions that are assignment-compatible with counter. statement is a simple or structured statement that does not change the value of counter.
The for statement assigns the value of initialValue to counter, then executes statement repeatedly, incrementing or decrementing counter after each iteration. (The for…to syntax increments counter, while the for…downto syntax decrements it.) When counter returns the same value as finalValue, statement is executed once more and the for statement terminates.
In other words, statement is executed once for every value in the range from initialValue to finalValue. If initialValue is equal to finalValue, statement is executed exactly once. If initialValue is greater than finalValue in a for…to statement, or less than finalValue in a for…downto statement, then statement is never executed. After the for statement terminates (provided this was not forced by a break or an exit procedure), the value of counter is undefined.
Example:
I use memo and button to write number form 1 to 10 in memo lines.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i :integer;
begin
memo1.Clear;
for i:=1 to 10 do
begin
memo1.Lines.Add(inttostr(i));
end;
end;
end.






Cool blog
Thanks, webmaster.
Cool blog
Thanks, webmaster.
Cool blog
Thanks, webmaster.