Skip to content

Variables and types

Every variable in NeoObjectPascal has a declared type. The declaration uses the var keyword, followed by the name, a colon, and the type:

npas
var idade: Integer;
var nome: String;

Values are assigned with the := operator (don't confuse it with =, which is the equality operator):

npas
begin
    var idade: Integer;
    idade := 30;
    WriteLn("Idade: ", idade);
end.
Saída
 Idade: 30 

Where to declare

You can declare variables in two places:

  • At the top of the file, before the main block.
  • Inside a block begin ... end, as an ordinary statement.
npas
var total: Integer;   // top-level declaration

begin
    total := 100;
    var imposto: Integer;   // declaration inside the block
    imposto := total / 10;
    WriteLn("Imposto: ", imposto);
end.
Saída
 Imposto: 10 

The ten types

NeoObjectPascal has ten built-in types:

TypeDescriptionLiteral examples
IntegerWhole numbers0, 42, -7
RealFloating-point numbers (double precision)3.14159, 5.0, -0.5
StringText"olá", 'mundo'
BooleanLogical valuetrue, false
ArrayOrdered collection of values[1, 2, 3], ["a", "b"]
ObjectGeneric type (instances, JSON/CSV, assorted values)new Pessoa("Ana")
DateCalendar date (ISO yyyy-MM-dd)today(), date(2026,12,25)
TimeTime of day (HH:mm:ss)currentTime(), time(10,30,0)
DateTimeCombined date and timenow()
CurrencyExact decimal money (no floating-point error)currency(199.90)

On top of these, Double and Float are aliases of Real (64-bit floating point) — use whichever name you prefer. The Date, Time, DateTime and Currency types are covered in detail in Dates, times & currency.

Literals and details of each type

Integer and Real

Integers are written directly: 10, -3, 0. Real numbers require digits on both sides of the decimal point:

npas
begin
    var meio: Real;
    meio := 0.5;    // correct
    WriteLn(meio);
end.
Saída
 0.5 

Real requires complete digits

Write 5.0, never 5. — the second form is invalid. Likewise, use 0.5 and not .5.

When you mix Integer and Real in an expression, the integer is automatically promoted to Real. The same happens when assigning an integer to a Real variable:

npas
begin
    var x: Real;
    x := 5;          // 5 becomes 5.0
    var y: Real;
    y := 2 * 3.5;    // Real result
    WriteLn("x = ", x);
    WriteLn("y = ", y);
end.
Saída
 x = 5.0 y = 7.0 

String

Strings can use double quotes or single quotes — both work the same way:

npas
begin
    var a: String;
    var b: String;
    a := "aspas duplas";
    b := 'aspas simples';
    WriteLn(a);
    WriteLn(b);
end.
Saída
 aspas duplas aspas simples 

The + operator concatenates strings. If either side is a String, + joins the values instead of adding them:

npas
begin
    var nome: String;
    nome := "Mundo";
    WriteLn("Olá, " + nome + "!");
end.
Saída
 Olá, Mundo! 

Boolean

A Boolean holds true or false (also accepted in uppercase, such as True or TRUE):

npas
begin
    var ativo: Boolean;
    ativo := true;
    WriteLn("Ativo: ", ativo);
end.
Saída
 Ativo: true 

Object

Object is the language's generic type. It holds class instances, results of JSON.parse/CSV.parse, and any value whose specific type you don't need to name:

npas
class Pessoa
    var nome: String;

    constructor Create(n: String)
    begin
        self.nome := n;
    end;

    public function saudar(): String
    begin
        return "Sou " + self.nome;
    end;
end;

var p: Object;

begin
    p := new Pessoa("Alice");
    WriteLn(p.saudar());
end.
Saída
 Sou Alice 

Choosing the type

Prefer the most specific type possible (Integer, String, etc.) and reserve Object for instances and dynamic data.

Now that you know how to declare variables, see how to combine them in Operators.