Pascal: Hello World

program ex1(input,output);
begin
  writeln(1, ' ', 2, ' ', 3);
  writeln('Hello world');
  readln;
end.

This will output 1 2 3 and Hello world on separate lines. Note the use of a space between the three numbers, otherwise the output would be '123'. The readln(a) command waits for the user to press Enter to finish the program.

In Delphi:

program ex1;
{$APPTYPE CONSOLE}
uses
    SysUtils;

begin

writeln(1, ' ', 2, ' ', 3);
  writeln('Hello world');
  readln;
end.

Create a console application with File/New/Console Application. Delphi adds the APPTYPE and the uses SysUtils lines so you can use Delphi as a DOS Pascal compiler. Use this for subsequent exercises.

Back to questions