mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
improve docs on if syntax. fixes #81
This commit is contained in:
parent
53b0b562e6
commit
733c17ad3a
@ -514,16 +514,26 @@ if statements
|
|||||||
Conditional execution means that the flow of execution changes based on certiain conditions,
|
Conditional execution means that the flow of execution changes based on certiain conditions,
|
||||||
rather than having fixed gotos or subroutine calls::
|
rather than having fixed gotos or subroutine calls::
|
||||||
|
|
||||||
if aa>4 goto overflow
|
if xx==5 {
|
||||||
|
yy = 99
|
||||||
|
zz = 42
|
||||||
|
} else {
|
||||||
|
aa = 3
|
||||||
|
bb = 9
|
||||||
|
}
|
||||||
|
|
||||||
if xx==3 yy = 4
|
if xx==5
|
||||||
if xx==3 yy = 4 else aa = 2
|
yy = 42
|
||||||
|
else if xx==6
|
||||||
|
yy = 43
|
||||||
|
else
|
||||||
|
yy = 44
|
||||||
|
|
||||||
if xx==5 {
|
if aa>4 goto some_label
|
||||||
yy = 99
|
|
||||||
} else {
|
if xx==3 yy = 4
|
||||||
aa = 3
|
|
||||||
}
|
if xx==3 yy = 4 else aa = 2
|
||||||
|
|
||||||
|
|
||||||
Conditional jumps (``if condition goto label``) are compiled using 6502's branching instructions (such as ``bne`` and ``bcc``) so
|
Conditional jumps (``if condition goto label``) are compiled using 6502's branching instructions (such as ``bne`` and ``bcc``) so
|
||||||
|
@ -783,19 +783,23 @@ Note: to do an indirect *JSR* to a routine with a varying address, you can use t
|
|||||||
(which is not very efficient) or you have to write a small piece of inline assembly.
|
(which is not very efficient) or you have to write a small piece of inline assembly.
|
||||||
|
|
||||||
|
|
||||||
Conditional execution
|
if statements
|
||||||
^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^
|
||||||
|
|
||||||
With the 'if' / 'else' statement you can execute code depending on the value of a condition::
|
With the 'if' / 'else' statement you can execute code depending on the value of a condition::
|
||||||
|
|
||||||
if <expression> <statements> [else <statements> ]
|
if <expression> <statements> [else <statements> ]
|
||||||
|
|
||||||
where <statements> can be just a single statement for instance just a ``goto``, or it can be a block such as this::
|
If <statements> is just a single statement, for instance just a ``goto`` or a single assignment,
|
||||||
|
it's possible to just write the statement without any curly braces.
|
||||||
|
However if <statements> is a block of multiple statements, you'll have to enclose it in curly braces::
|
||||||
|
|
||||||
if <expression> {
|
if <expression> {
|
||||||
<statements>
|
<statements>
|
||||||
|
} else if <expression> {
|
||||||
|
<statements>
|
||||||
} else {
|
} else {
|
||||||
<alternative statements>
|
<statements>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -807,7 +811,7 @@ itself defines on what status register bit it should branch on::
|
|||||||
|
|
||||||
if_XX <statements> [else <statements> ]
|
if_XX <statements> [else <statements> ]
|
||||||
|
|
||||||
where <statements> can be just a single statement for instance just a ``goto``, or it can be a block such as this::
|
where <statements> can be just a single statement or a block again::
|
||||||
|
|
||||||
if_XX {
|
if_XX {
|
||||||
<statements>
|
<statements>
|
||||||
|
Loading…
Reference in New Issue
Block a user