Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one initialize multiple variables of some type in one line?

I have been trying to write as less code as possible. So, I use:

MyBoolean := Memo1.Text <> '';

instead of

if Memo1.Text = '' then
  MyBoolean := true
else
  MyBoolean := false;

Declare and initialize

var
  myGlobal: integer = 99;

to declare and initialize global variable. I would like to do the same for local variables, but seems it is not possible, so, I wonder if there is a way to initialize multiple variables of some type in one line, like in C

int x, y, z;
x=y=z=0;

Thank you.

like image 232
Edijs Kolesnikovičs Avatar asked Apr 27 '14 09:04

Edijs Kolesnikovičs


2 Answers

In C assignment is an expression (returns a value).

In Pascal assignment is a statement (does not return a value).

The difference has some interesting consequences. For example in C both

while (x=0)

and

while (x==0)

are syntactically valid constructions (it is the source of innumerable errors) while in Pascal

while (x:=0)

is syntactically invalid because x:=0 is a statement.

like image 198
kludg Avatar answered Nov 18 '22 10:11

kludg


You can only initialize a single local variable per statement.

like image 20
David Heffernan Avatar answered Nov 18 '22 10:11

David Heffernan