mirror of
https://github.com/irmen/prog8.git
synced 2024-11-27 03:50:27 +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)
|
||||
- subroutines (nested named scope)
|
||||
|
||||
.. note::
|
||||
Unlike many other programming languages, a new scope is *not* created inside
|
||||
for, while and repeat statements, nor for the if statement and branching conditionals.
|
||||
This can be a bit restrictive because as a programmer you have to think harder about what variables you
|
||||
want to use inside a subroutine. But it is done precisely for this reason: memory in prog8's
|
||||
.. important::
|
||||
Unlike most other programming languages, a new scope is *not* created inside
|
||||
for, while and repeat statements, the if statement, and the branching conditionals.
|
||||
These all share the same scope from the subroutine they're defined in.
|
||||
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.
|
||||
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
|
||||
@ -174,7 +178,7 @@ Variables and values
|
||||
--------------------
|
||||
|
||||
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.
|
||||
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::
|
||||
|
@ -5,29 +5,33 @@
|
||||
|
||||
main {
|
||||
|
||||
sub subje(ubyte arg1) {
|
||||
ubyte yy=33
|
||||
sub subje() {
|
||||
ubyte a1
|
||||
ubyte a2
|
||||
ubyte zz
|
||||
ubyte[5] array1 = [1,2,3,4,5]
|
||||
|
||||
c64scr.print_ub(arg1)
|
||||
c64.CHROUT(',')
|
||||
c64scr.print_ub(yy)
|
||||
c64.CHROUT(',')
|
||||
c64scr.print_ub(zz)
|
||||
c64.CHROUT('\n')
|
||||
yy++
|
||||
A=zz
|
||||
Y=array1[2]
|
||||
for a1 in 1 to 3 {
|
||||
ubyte qq = 100 ; TODO should be inited here, and not in the subroutine.
|
||||
for a2 in 1 to 3 {
|
||||
ubyte zz = 100 ; TODO should be inited here, and not in the subroutine.
|
||||
c64scr.print_ub(a1)
|
||||
c64.CHROUT(',')
|
||||
c64scr.print_ub(a2)
|
||||
c64.CHROUT(',')
|
||||
c64scr.print_ub(qq) ; TODO qq shoud be 100..103 repeated three times...
|
||||
c64.CHROUT(',')
|
||||
c64scr.print_ub(zz) ; TODO zz should always be 100...
|
||||
c64.CHROUT('\n')
|
||||
qq++
|
||||
zz++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub start() {
|
||||
ubyte zz2
|
||||
A=zz2
|
||||
subje(111)
|
||||
subje(112)
|
||||
subje(113)
|
||||
subje(114)
|
||||
subje()
|
||||
c64.CHROUT('\n')
|
||||
subje()
|
||||
c64.CHROUT('\n')
|
||||
return
|
||||
|
||||
; ubyte ub1
|
||||
|
Loading…
Reference in New Issue
Block a user