Hello World (Pascal)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL

This is a simple Pascal program that prints a string to the console, then prints the integers 1 through 10 using a simple for loop.

The first line of each Pascal program is a line stating the program name. The name is followed by an argument list, which for programs writing to standard output must contain the name output, and for programs reading from standard input contains the name input.

Many Pascal implementations ignore the argument list and let you omit it. Often even the program line itself can be omitted. However, to be standard conforming, the line must not be omitted, and only programs doing no I/O may omit the parameter list.

Since the program does only output something, the argument list consists just of output.

program helloworld(output);

In Pascal, variables are defined outside the block they belong to. This program need an integer variable for the loop.

  I: Integer;

Now follows the code block of the main program. The code block consists of statements enclose by a begin/end pair. After the end, the program is finished; this is indicated by putting a full stop after the end.


The first statement just writes "Hello, World!" to standard output. By using WriteLn, it is ensured that afterwards, a new line is started. Using Write instead would not start a new line.

WriteLn('Hello, World!');

After that, there's a loop printing the values from 1 to 10, each one on its own line.

for I := 1 to 10 do
Download code
Personal tools