-3

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

Varest
  • 57
  • 1
  • 11
  • 5
    Perhaps a text book might help. Trying to guess your way to knowledge is unlikely to yield much of use. – David Heffernan Nov 12 '19 at 17:54
  • 3
    My friendly advice is to read about elementary syntax rules in the Freepascal documentation. It will save you a lot of time and prevent frustration. – Tom Brunberg Nov 12 '19 at 17:56
  • Never in a million years would a programmer realize to type "void Main(void) to start a program, yet this is the magic that declares it in C. Python doesn't know how to declare the end of a function and return a value. Many languages use return, which is so much goto. Scattering variable declarations throughout a program is terrible for CPU and memory in any language, because of how computers work. First syntax is actually correct - as you would have found out, if only you had bothered to look up a single programming example to know how! – Henrik Erlandsson Aug 31 '22 at 21:20

2 Answers2

3

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

Miguel Cabrera
  • 191
  • 1
  • 6
2

It's been a very long time since I wrote Pascal, but IIRC, the assignment operator is := (aka the walrus sign). = is the equality test operator.

Try this:

var current: string;
current := '1.6';
Code Different
  • 90,614
  • 16
  • 144
  • 163