Hello World is a computer program that prints the line "Hello World" somewhere on a display device. It is a tradition in teaching computer programming to start with a Hello World program. Although it is extremely simple, it allows us to discuss a number of the basic syntax rules of Object Pascal. To get started, open your Unit1/Workspace folder (if you do not have this folder on your computer or do not know where it is refer to Appendix A). Double-click on either Workspace.lpi or Workspace.lpr (both files open the same program). You'll notice that a simple text file is displayed which contains some simple source code. For the first several projects, we will use this Workspace project as a template. In other words, to make things faster we will not save our work to a new project but instead will copy and paste new code into the editor. When we move to more complicated projects we will create new project templates so you can save your work. For now, copy and paste the following code into the editor:
{$APPTYPE CONSOLE}
program Workspace;

begin
  {This program will print Hello World to the screen.}
  Writeln('Hello World!');
  Readln;
end.
The first thing you should know how to do is to compile a program. Assuming you are using the default key shortcut mappings, all you have to do is press Control+F9. If you press F9 only, the program will both compile and run. Press Control+F9 now. You can use this keyboard shortcut to check the syntax of code you enter without running the program.

Line 1 is a compiler directive. Compiler directives allow us to change the behavior of the compiler while it is parsing the code. In Unit I, we will not deal with compiler directives in depth. We use it here only because we must tell the compiler that we are creating a console application. A console application is a program that has only a text-based interface.

Line 2 defines the program name. It should always match the file name of the source code. You will notice the use of the reserved word program and the identifier HelloWorldConsole followed by the semicolon symbol. The individual symbols such as keywords, identifiers, and semicolons in any programming language are known as tokens. The compiler reads tokens and assigns predefined meanings to them. Although it may be tempting to think that "program" and "HelloWorldConsole" are both identifiers, the compiler knows a set of "reserved words" (also known as keywords) which help define the valid syntax of a language. Object Pascal is case-insensitive which means that "program" and "Program" are both the same reserved word. Reserved words cannot be used as identifiers. You can try to change "program HelloWorldConsole" to "program Program" and press Ctrl+F9. Note also that the syntax higlighter automatically changes the color to the reserved word color instead of the identifier color. The compiler returns an error message that an identifier was expected. Now change this line back to "program HelloWorldConsole".

Line 3 is witespace. Whitespace has no defined meaning in Object Pascal which means that the compiler just ignores it as if the uses clause and the begin line were adjacent. While it may seem trivial to discuss whitespace, some languages (such as Matlab and Python) use parts of whitespace (line breaks and tab characters respectively) to actually mean something in the source code.

Line 4 contains the "begin" reserved word. In Object Pascal, "begin" and "end" define a compound statement. Compound statements are used to group simple statements. Although compound statements are universal to programming languages, different languages use different symbols (e.g., C uses curly braces { } ).

Line 5 is a comment. Comments are used to explain code in plain English as well as to inactivate portions of code since the compiler treats comments as whitespace. Explaining code in comments is known as documentation and is extremely important for two reasons. First, your code should be readable by others. Second, your code should be readable by you because after a month you will have forgotten everything about it and will not understand your own code without good comments. In Object Pascal, comments can be multi-line or single line. Multi-line comments are defined by curly braces { } or parenthesis-asterisks (* *) . Single line comments are defined by double front-slashes // and terminate automatically at the end of a line. You should play around with these symbols in the editor to see what happens. By convention, curly brace { } and double slash // comments are generally used for documentation and parenthesis-asterisk (*  *) comments are used to inactivate blocks of code. You may also notice a similarity between curly brace { } comments and compiler directives. Compiler directives always have a left curly brace followed by a dollar sign {$ } which allows the compiler to distinguish them from comments. Like comments, compiler directives are not considered a part of the actual code. The difference is that compiler directives can change the compiler's behavior while comments do nothing.

Line 6 is the Writeln command. In Object Pascal, commands are calls to either procedures or functions. We will discuss the difference between procedures and functions in Chapter 2. Together, procedures and functions are known as subroutines. Subroutines are like mini-programs inside of a larger program which are called to perform some specified action. When we call a subroutine, the processor's execution shifts to a different location in the code and executes the code at that new location. When the subroutine is done, the processor returns to the original location in the code and continues executing where it left off.

The Writeln subroutine writes some specified text to the screen. In programming terms, text is known as a literal string, or a sequence of numbers, letters, or symbols that are meant to be interpreted literally as is instead of being treated as code. You will notice also that strings in Object Pascal start and stop with a single quote (') and are given a color different than the rest of the code.
Writeln('Hello World!');
With how it is written now, the literal string 'Hello World!' is passed as an argument (sometimes called a parameter) to the subroutine Writeln which then can do some processing on or with this argument. In the case of Writeln, it prints the string to the screen.

Line 7 is the Readln command. Without it, the program would write Hello World to the screen and then exit immediately. Readln forces the program to wait until the enter key is pressed before continuing to the next statement (which in this case is the end of the program). In other words, Readln does not return from the call until enter is pressed.

Finally, line 8 is the "end" reserved word. Notice that the end of the program ends with a period instead of a semicolon. This is similar to English grammar in which several smaller ideas are separated by semicolons and the entire sentence is terminated with a period.

Now press F9 (not Ctrl+F9) and the program will run and print Hello World on the screen. You can press the enter key to terminate the program. If all goes well, the following is what you should have seen.
As we mentioned above, console apps interact with a user through only a text-based interface. The creation of the console window is left entirely to the operating system (which is why we use {$APPTYPE CONSOLE} to tell the compiler a window will need to be created. In terms of a user interface, console applications are one of the simplest types of applications that can be created. Keep in mind we said "in terms of a user interface" when refering to the simplicity of console applications. Some of the most sophisticated programs used by scientists and engineers have only console interfaces. Programs can also not have an interface at all. These types of programs are called services or daemons (the latter word daemon refers to the invisibility of the program and does not imply malicious intent). Had we wanted to create a program that runs in the background with no interface, we could have simply left out the {$APPTYPE CONSOLE} directive. We of course would not have been able to use Writeln or Readln though. More commonly, programs have what is known as a Graphical User Interface (GUI, pronounced gooey). In the next section, we will create a simple Hello World graphical application.