while <condition> do
begin
statement block
end;
These are useful for things like waiting until the user presses a key
or waiting until a number entered by the user is valid.
For instance you might say :
var
In this loop as long as condition is true (in this case code <> 0)
it will execute the code between the begin and the corresponding
end. You can miss out the begin and end but then you will only be
able to have one line of code, or even no lines of code at all if you want.
   valueIn : String; {This will be the value the user enters}
   I, code : Integer;
begin
   valueIn := 'abc'; {Fill it with a non integer value}
   code := 1;
   while code <> 0 do {While code is zero do the following}
   begin
    writeln('Enter a number:');
    readln(valueIn);
    val(valueIn, I, code);
    {Move the integer value of valueIn to I or if it isn't an}
    {integer then code will be something other than 0. NB: code is}
    {the error code. I can only hold integers so there is an error}
    {raised when the string can't be converted to an integer}
   end;
end.
eg:  while not keypressed do;
In the above example as long as there is not a key pressed the instructions in the loop are executed. Since there are no instructions in the loop this stops the program until the user presses a key.
For loops are more useful for iterating through an array.
For instance you might want to add 1 to each integer in an array...
for variable := value1 [to|downto] value2 do
begin
   statement block
end;
var
   i : Integer; {This will be the counter for the loop}
   myArray : array[1..30] of Integer; {See arrays for this}
begin
   for i := 1 to 30 do
    myArray[i] := myArray[i] + 1;
end.
i := 1;
while i <= 6 do
begin
writeln(i);
i := i + 1;
end;
i := 1;
repeat
begin
writeln(i);
i := i + 1;
until i > 6;