May 2004
Intermediate to advanced
888 pages
22h 31m
English
A loop is a construct that enables you to repeatedly perform some type of action. Delphi’s loop constructs are very similar to what you should be familiar with from your experience with other languages, so we don’t spend any time teaching you about loops. This section describes the various loop constructs you can use in Delphi.
A for loop is ideal when you need to repeat an action a predetermined number of times. Here’s an example, albeit not a very useful one, of a for loop that adds the loop index to a variable 10 times:
var
I, X: Integer;
begin
X := 0;
for I := 1 to 10 do
inc(X, I);
end.The C# equivalent of the preceding example is as follows:
void main()
{
int x = 0;
for(int i=1; i<=10; i++)
x += i;
}Here’s the Visual ...
Read now
Unlock full access