variablespascalfreepascal

Pascal | Initializing variables


The following syntax examples are incorrect ways to initialize a variable in pascal:

var current: string = '1.6';

Error message: Column 21: Semicolon (;) expected.

var current: string;
current = '1.6';

Error message: Column 1: Duplicate identifier 'current'.

Correct syntax to initialize a variable in Pascal:

var current: string;
    begin
current := '1.6';
    end

Source: https://www.freepascal.org/docs-html/current/ref/refse25.html#x56-740004.5


Solution

  • I haven't codified in Pascal for a long time, but the assignation of a variable uses the := operator (assigment operator), = operator is for comparisitions. Otherwise you need to add the main program block, like this:

    Var
       current: string;
    
    Begin
       current := '1.6';
    End.
    

    I hope can be useful for you.

    More info here: https://www.freepascal.org/docs-html/ref/refse101.html