mirror of
https://github.com/irmen/prog8.git
synced 2024-09-08 10:55:08 +00:00
doc
This commit is contained in:
parent
0c561d8528
commit
efef205fcf
@ -135,14 +135,18 @@ Scopes are created using either of these two statements:
|
|||||||
- blocks (top-level named scope)
|
- blocks (top-level named scope)
|
||||||
- subroutines (nested named scope)
|
- subroutines (nested named scope)
|
||||||
|
|
||||||
.. note::
|
.. important::
|
||||||
Unlike many other programming languages, a new scope is *not* created inside
|
Unlike most other programming languages, a new scope is *not* created inside
|
||||||
for, while and repeat statements, nor for the if statement and branching conditionals.
|
for, while and repeat statements, the if statement, and the branching conditionals.
|
||||||
This can be a bit restrictive because as a programmer you have to think harder about what variables you
|
These all share the same scope from the subroutine they're defined in.
|
||||||
want to use inside a subroutine. But it is done precisely for this reason: memory in prog8's
|
You can define variables in these blocks, but these will be treated as if they
|
||||||
|
were defined in the subroutine instead.
|
||||||
|
This can seem a bit restrictive because you have to think harder about what variables you
|
||||||
|
want to use inside the subroutine, to avoid clashes.
|
||||||
|
But this decision was made for a good reason: memory in prog8's
|
||||||
target systems is usually very limited and it would be a waste to allocate a lot of variables.
|
target systems is usually very limited and it would be a waste to allocate a lot of variables.
|
||||||
The prog8 compiler is not yet advanced enough to be able to share or overlap
|
The prog8 compiler is not yet advanced enough to be able to share or overlap
|
||||||
variables intelligently. So for now that is something the programmer has to think about.
|
variables intelligently. So for now that is something you have to think about yourself.
|
||||||
|
|
||||||
|
|
||||||
Program Start and Entry Point
|
Program Start and Entry Point
|
||||||
@ -174,7 +178,7 @@ Variables and values
|
|||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
Variables are named values that can change during the execution of the program.
|
Variables are named values that can change during the execution of the program.
|
||||||
They can be defined inside any scope (blocks, subroutines, for loops, etc.) See :ref:`Scopes <scopes>`.
|
They can be defined inside any scope (blocks, subroutines etc.) See :ref:`Scopes <scopes>`.
|
||||||
When declaring a numeric variable it is possible to specify the initial value, if you don't want it to be zero.
|
When declaring a numeric variable it is possible to specify the initial value, if you don't want it to be zero.
|
||||||
For other data types it is required to specify that initial value it should get.
|
For other data types it is required to specify that initial value it should get.
|
||||||
Values will usually be part of an expression or assignment statement::
|
Values will usually be part of an expression or assignment statement::
|
||||||
|
@ -5,29 +5,33 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub subje(ubyte arg1) {
|
sub subje() {
|
||||||
ubyte yy=33
|
ubyte a1
|
||||||
|
ubyte a2
|
||||||
ubyte zz
|
ubyte zz
|
||||||
ubyte[5] array1 = [1,2,3,4,5]
|
for a1 in 1 to 3 {
|
||||||
|
ubyte qq = 100 ; TODO should be inited here, and not in the subroutine.
|
||||||
c64scr.print_ub(arg1)
|
for a2 in 1 to 3 {
|
||||||
c64.CHROUT(',')
|
ubyte zz = 100 ; TODO should be inited here, and not in the subroutine.
|
||||||
c64scr.print_ub(yy)
|
c64scr.print_ub(a1)
|
||||||
c64.CHROUT(',')
|
c64.CHROUT(',')
|
||||||
c64scr.print_ub(zz)
|
c64scr.print_ub(a2)
|
||||||
c64.CHROUT('\n')
|
c64.CHROUT(',')
|
||||||
yy++
|
c64scr.print_ub(qq) ; TODO qq shoud be 100..103 repeated three times...
|
||||||
A=zz
|
c64.CHROUT(',')
|
||||||
Y=array1[2]
|
c64scr.print_ub(zz) ; TODO zz should always be 100...
|
||||||
|
c64.CHROUT('\n')
|
||||||
|
qq++
|
||||||
|
zz++
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte zz2
|
subje()
|
||||||
A=zz2
|
c64.CHROUT('\n')
|
||||||
subje(111)
|
subje()
|
||||||
subje(112)
|
c64.CHROUT('\n')
|
||||||
subje(113)
|
|
||||||
subje(114)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
; ubyte ub1
|
; ubyte ub1
|
||||||
|
Loading…
Reference in New Issue
Block a user