Lesson 1: Advanced 'If' Statements
by Anthony Bush
Take a look at this 'If' statement:
:If B=0
:A-1->A
You know that the command following the if statement is only executed if the statement "B=0" is true. If it is not true, then the command will not be executed. Note that all logic statements return a value of true (1) or false (0). Take the logic statement "B=0" for example. If it is true (i.e. B is equal to zero) then it will return a value of (1). If it is false (i.e. B is not equal to zero) then it will return a value of (0). Ok, now look back at the if statement:
:If B=0
:A-1->A
When B=0, then you subtract 1 from A, when it is not, you do nothing. So, you could rewrite it to look like this:
:A-(B=0)->A
When B equals zero then (B=0) will have a value of 1, right? When B is not equal to zero, (B=0) will have a value of 0. So what if you wanted to subtract 2 from A? Well, it would look like this:
:A-2(B=0)->A
Get it? It's pretty simple, just play around with it. You can really speed up your programs when using this. Below is an example of a place to use this.
This is a simple sprite routine before revising the if statements:
:ClrHome
:8->A
:4->B
:Output(B,A,"X")
:Repeat C=105
:Repeat C=24 and A>1 or C=25 and B>1 or C=26 and A<16 or C=34 and B<8
:getKey->C
:End
:Output(B,A," ")
:If C=24
:A-1->A
:If C=25
:B-1->B
:If C=26
:A+1->A
:If C=34
:B+1->B
:Output(B,A,"X")
:End

This is what it looks like after revising:
:ClrHome
:8->A
:4->B
:Output(B,A,"X")
:Repeat C=105
:Repeat C=24 and A>1 or C=25 and B>1 or C=26 and A<16 or C=34 and B<8
:getKey->C
:End
:Output(B,A," ")
:A-(C=24)+(C=26)->A
:B-(C=25)+(C=34)->B
:Output(B,A,"X")
:End
See how the if statements were removed? Well, that's all for now.

Home


1