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.
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.
You can only initialize a single local variable per statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With