Values in Pascal

Pascal has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

program Values;

uses
  SysUtils;

begin
  // Strings, which can be concatenated with '+'
  WriteLn('pascal' + 'lang');

  // Integers and floats
  WriteLn('1+1 = ', 1 + 1);
  WriteLn('7.0/3.0 = ', 7.0 / 3.0 : 0 : 16);

  // Booleans, with boolean operators as you'd expect
  WriteLn(True and False);
  WriteLn(True or False);
  WriteLn(not True);
end.

To run the program, save it as values.pas and use a Pascal compiler like Free Pascal:

$ fpc values.pas
$ ./values
pascallang
1+1 = 2
7.0/3.0 = 2.3333333333333335
FALSE
TRUE
FALSE

In this Pascal program:

  1. We use WriteLn instead of fmt.Println to output to the console.
  2. String concatenation is done with the + operator, similar to many other languages.
  3. Integer and float operations work as expected.
  4. Boolean operations use and, or, and not instead of &&, ||, and !.
  5. Pascal uses begin and end. to denote the main program block, rather than curly braces.
  6. The : 0 : 16 in the float division line specifies the format of the output (0 digits before the decimal point, 16 after).

Note that Pascal is case-insensitive, so TRUE, True, and true are all valid and equivalent.