LearnStanmorephysics

Grade 10 · Delphi Foundations

FOR loops

Grade 10 · Loops & first strings · Lesson and coding task · about 12 minutes

Open this task in the Delphi workspace →

A FOR loop repeats code a known number of times. The loop variable must be an Integer declared in var:

for i := 1 to 5 do
  memOutput.Lines.Add('Lap ' + IntToStr(i));

for i := 10 downto 1 do    // counts backwards
  memOutput.Lines.Add(IntToStr(i));

If the body has more than one statement, wrap it in begin … end;. The loop variable takes each value in turn — that is what makes times tables, totals and patterns possible.

Your task

Print the full times table (1× to 12×) of any number the user enters, like the poster on your primary school wall:

1 x 7 = 7
2 x 7 = 14
…
12 x 7 = 84

What you will do

Hints
  1. for i := 1 to 12 do
  2. Each line joins three numbers: IntToStr(i) + ' x ' + IntToStr(iNum) + ' = ' + IntToStr(i * iNum)
  3. Watch the spaces around x and = — the test checks them exactly.
Model solution
procedure TfrmTables.btnShowClick(Sender: TObject);
var
  i, iNum : Integer;
begin
  iNum := StrToInt(edtNumber.Text);
  for i := 1 to 12 do
    memOutput.Lines.Add(IntToStr(i) + ' x ' + IntToStr(iNum) + ' = ' + IntToStr(i * iNum));
end;

About this material

This platform provides original CAPS-aligned practice material and study tools. Content is machine-verified and has not been reviewed by subject specialists. It is not affiliated with or endorsed by the Department of Basic Education. Learners should also use official past papers and consult their teachers where uncertain.