Lesson 1 · 1 of 20
Hello, world · Pascal
Your first Pascal program: WriteLn prints text and results to the console. Compile it with Free Pascal or run it with F9 in DMarlon Studio.

A Pascal program starts with its name, program main;, and what it does goes between `begin` and `end.`, with a full stop marking where it finishes. Each statement ends with a semicolon.
`WriteLn` writes whatever you put inside the brackets to the console and moves to the next line. Text goes between single quotes, 'Hello, world!': it is a string. `Write` does the same without the line break, which is why Write('Two plus three is ') and WriteLn(2 + 3) end up on the same line.
Numbers go without quotes, and Pascal works out the sum before printing it: 7 * 24 comes out as 168. With commas, a single WriteLn prints several values one after another with nothing in between (you add the spaces inside the quotes). A WriteLn with no brackets prints an empty line.
Comments are not run: // comments out the rest of the line and { ... } wraps a comment that can span several lines. In DMarlon Studio, Pascal powers desktop apps built with Lazarus as well as the Console target, where this program runs with F9.
Code · main.pas
program main;{ The program runs from begin to the final end with a full stop. }begin WriteLn('Hello, world!'); WriteLn('Welcome to Pascal.'); // Write stays on the same line; WriteLn moves to the next one. Write('Two plus three is '); WriteLn(2 + 3); // Several values, separated by commas, in one WriteLn. WriteLn('A week has ', 7 * 24, ' hours.'); WriteLn; WriteLn('Goodbye!');end.Output · fpc main.pas && ./main
Hello, world! Welcome to Pascal. Two plus three is 5 A week has 168 hours. Goodbye!
Key points
- The program goes between
beginandend., with a full stop. WriteLnprints and moves to a new line;Writedoes not.- Text goes between single quotes; numbers do not.
- Commas separate several values in one
WriteLn. //and{ }are comments.
Exercise
Make the program print your name and, on another line, how many minutes there are in a day (let Pascal work it out with 24 * 60).