A better way for if....then?
Archiver
Posts: 46,084
Maybe someone can give me some pointers on a better way to use
if...then statements, or even an alternative. Here is what I am
trying to do:
if x < y then z = z + 1
if x > y then z = z – 1
if z < 500 then z = 500
if z > 1000 then z = 1000
From what I can see, this can't be done directly but you have to
call an address (or label) such as
if x < y then increasez
and use
increasez:
z = z + 1
return
While I understand this can be done, it sure seems like there has to
be a better way of doing it. Any insight would be helpful.
Note: That isn't the complete code above, but hopefully will be
enough to give you an idea of what my question is.
Hank
if...then statements, or even an alternative. Here is what I am
trying to do:
if x < y then z = z + 1
if x > y then z = z – 1
if z < 500 then z = 500
if z > 1000 then z = 1000
From what I can see, this can't be done directly but you have to
call an address (or label) such as
if x < y then increasez
and use
increasez:
z = z + 1
return
While I understand this can be done, it sure seems like there has to
be a better way of doing it. Any insight would be helpful.
Note: That isn't the complete code above, but hopefully will be
enough to give you an idea of what my question is.
Hank
Comments
That kind of logic becomes much easier to code in the new Parallax
IDE, version 2.5, now available for free download on their web site.
With that, you can write those statements exactly as you have them,
or you can use the new CASE statement.
If you prefer the old tried and true Stamp code, here are a couple of
ways to code your first if-then statement:
if x>=y then skipincrement
z=z+1 ' only if x<y
skipincrement:
another way, computed instead of if-then:
z= z + (x max y - y max 1)
the expression in (..) equals 1 if x<y, zero if x>=y.
-- Tracy
>Maybe someone can give me some pointers on a better way to use
>if...then statements, or even an alternative. Here is what I am
>trying to do:
>
>if x < y then z = z + 1
>if x > y then z = z – 1
>if z < 500 then z = 500
>if z > 1000 then z = 1000
>
>>From what I can see, this can't be done directly but you have to
>call an address (or label) such as
>
>if x < y then increasez
>
>and use
>
>increasez:
>z = z + 1
>return
This won't work, because "increasez" is subroutine, but the if-then
is a simple branch.
>While I understand this can be done, it sure seems like there has to
>be a better way of doing it. Any insight would be helpful.
>
>Note: That isn't the complete code above, but hopefully will be
>enough to give you an idea of what my question is.
>
>Hank
Decided to switch over to the 2.5 IDE and it works fine... now I just
have to study the other options you gave.
Hank
--- In basicstamps@yahoogroups.com, Tracy Allen <tracy@e...> wrote:
> Hi Hank,
>
> That kind of logic becomes much easier to code in the new Parallax
> IDE, version 2.5, now available for free download on their web
site.
> With that, you can write those statements exactly as you have them,
> or you can use the new CASE statement.
>
> If you prefer the old tried and true Stamp code, here are a couple
of
> ways to code your first if-then statement:
>
> if x>=y then skipincrement
> z=z+1 ' only if x<y
> skipincrement:
>
> another way, computed instead of if-then:
>
> z= z + (x max y - y max 1)
>
> the expression in (..) equals 1 if x<y, zero if x>=y.
>
>
>
> -- Tracy
>
> >Maybe someone can give me some pointers on a better way to use
> >if...then statements, or even an alternative. Here is what I am
> >trying to do:
> >
> >if x < y then z = z + 1
> >if x > y then z = z – 1
> >if z < 500 then z = 500
> >if z > 1000 then z = 1000
> >
> >>From what I can see, this can't be done directly but you have to
> >call an address (or label) such as
> >
> >if x < y then increasez
> >
> >and use
> >
> >increasez:
> >z = z + 1
> >return
>
> This won't work, because "increasez" is subroutine, but the if-then
> is a simple branch.
>
>
> >While I understand this can be done, it sure seems like there has
to
> >be a better way of doing it. Any insight would be helpful.
> >
> >Note: That isn't the complete code above, but hopefully will be
> >enough to give you an idea of what my question is.
> >
> >Hank