17-06-19, 08:36 PM
Continue
كود :
var
i : Integer;
s : string;
begin
s := '';
// A big loop
for i := 1 to 9 do
begin
// Skip loop processing for certain values of i
if (i = 3) or (i = 7) then Continue;
s := s + IntToStr(i);
s := s + ' ';
end;
// Show the string created by the above loop
ShowMessage('s = '+s);
end;إقتباس :s = 1 2 4 5 6 8 9
Do
كود :
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;إقتباس :For loop, i = 1For loop, i = 2For loop, i = 3While loop, i = 4While loop, i = 5
DownTo
كود :
var
i : Integer;
begin
// Loop 5 times
for i := (10 div 2) DownTo 1 do
ShowMessage('i = '+IntToStr(i));
end;إقتباس :i = 5i = 4i = 3i = 2i = 1
كود :
var
c : char;
begin
// Loop 5 times
for c := 'E' DownTo 'A' do
ShowMessage('c = '+c);
end;إقتباس :c = Ec = Dc = Cc = Bc = A
كود :
var
suit : (Hearts, Clubs, Diamonds, Spades);
begin
// Loop 3 times
for suit := Diamonds DownTo Hearts do
ShowMessage('Suit = '+IntToStr(Ord(suit)));
end;إقتباس :Suit = 2Suit = 1Suit = 0
For
كود :
var
i : Integer;
begin
// Loop 5 times
For i := 1 to (10 div 2) do
ShowMessage('i = '+IntToStr(i));
end;إقتباس :i = 1i = 2i = 3i = 4i = 5
كود :
var
c : char;
begin
// Loop 5 times - downwards
For c := 'E' downto 'A' do
ShowMessage('c = '+c);
end;إقتباس :c = Ec = Dc = Cc = Bc = A
كود :
var
suit : (Hearts, Clubs, Diamonds, Spades);
begin
// Loop 3 times
For suit := Hearts to Diamonds do
ShowMessage('Suit = '+IntToStr(Ord(suit)));
end;إقتباس :Suit = 0Suit = 1Suit = 2
Repeat
كود :
var
num, sqrNum : Integer;
begin
num := 1;
sqrNum := num * num;
// Display squares of integers until we reach 100 in value
Repeat
// Show the square of num
ShowMessage(IntToStr(num)+' squared = '+IntToStr(sqrNum));
// Increment the number
Inc(num);
// Square the number
sqrNum := num * num;
until sqrNum > 100;
end;إقتباس :1 squared = 12 squared = 43 squared = 94 squared = 165 squared = 256 squared = 367 squared = 498 squared = 649 squared = 8110 squared = 100
Until
كود :
var
num, sqrNum : Integer;
begin
num := 1;
sqrNum := num * num;
// Display squares of integers until we reach 100 in value
Repeat
// Show the square of num
ShowMessage(IntToStr(num)+' squared = '+IntToStr(sqrNum));
// Increment the number
Inc(num);
// Square the number
sqrNum := num * num;
Until sqrNum > 100;
end;إقتباس :1 squared = 12 squared = 43 squared = 94 squared = 165 squared = 256 squared = 367 squared = 498 squared = 649 squared = 8110 squared = 100
While
كود :
var
num, sqrNum : Integer;
begin
num := 1;
sqrNum := num * num;
// Display squares of integers until we reach 100 in value
While sqrNum <= 100 do
begin
// Show the square of num
ShowMessage(IntToStr(num)+' squared = '+IntToStr(sqrNum));
// Increment the number
Inc(num);
// Square the number
sqrNum := num * num;
end;
end;إقتباس :1 squared = 12 squared = 43 squared = 94 squared = 165 squared = 256 squared = 367 squared = 498 squared = 649 squared = 8110 squared = 100