How to resolve the algorithm Repeat step by step in the Delphi programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Repeat step by step in the Delphi programming language

Table of Contents

Problem Statement

Write a procedure which accepts as arguments another procedure and a positive integer. The latter procedure is executed a number of times equal to the accepted integer.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Repeat step by step in the Delphi programming language

Source code in the delphi programming language

program Repeater;

{$APPTYPE CONSOLE}
{$R *.res}

type
  TSimpleProc = procedure;     // Can also define types for procedures (& functions) which
                               // require params.

procedure Once;
begin
  writeln('Hello World');
end;

procedure Iterate(proc : TSimpleProc; Iterations : integer);
var
  i : integer;
begin
  for i := 1 to Iterations do
    proc;
end;

begin
  Iterate(Once, 3);
  readln;
end.


program Repeater;

{$APPTYPE CONSOLE}
{$R *.res}

uses
  System.SysUtils;

procedure Iterate(proc: TProc; Iterations: integer);
var
  i: integer;
begin
  for i := 1 to Iterations do
    proc;
end;

begin
  Iterate(
    procedure
    begin
      writeln('Hello World');
    end, 3);
  readln;
end.


  

You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the Red programming language
You may also check:How to resolve the algorithm Undefined values step by step in the R programming language
You may also check:How to resolve the algorithm Verify distribution uniformity/Naive step by step in the Nim programming language
You may also check:How to resolve the algorithm Terminal control/Ringing the terminal bell step by step in the Scala programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Nutt programming language