Entry
Bbcbasic: Variable: Initialize: Can you declare the value of a variable when you initialize it?
Aug 12th, 2007 11:14
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 05 Juny 2005 - 02:59 pm -----------------------
Bbcbasic: Variable: Initialize: Can you declare the value of a
variable when you initialize it?
---
No.
---
What does happen is when you use LOCAL then
that variable is initialized by default to
zero or the empty string.
You have thus to set that variable after you used
LOCAL.
===
e.g.
This will give a syntax error:
('not in a function')
--- cut here: begin --------------------------------------------------
PROCt
END
:
:
:
DEF PROCt
LOCAL myinteger1 = 10
END
--- cut here: end ----------------------------------------------------
---
e.g.
This will not give a syntax error:
--- cut here: begin --------------------------------------------------
PROCt
END
:
:
:
DEF PROCt
LOCAL myinteger1
myinteger1 = 10
END
--- cut here: end ----------------------------------------------------
===
But what you can use alternatively is declaring the variable
after the LOCAL
E.g.
--- cut here: begin --------------------------------------------------
PROCHelloWorld
END
:
:
:
DEF PROCHelloWorld
LOCAL K% : K% = 1
LOCAL D% : D% = 2
PRINT K%
PRINT D%
ENDPROC
--- cut here: end ----------------------------------------------------
If you run this, it will print
1
2
===
Internet: see also:
---
----------------------------------------------------------------------