Page 1 of 1

A problem of Conditions

Posted: Sun Apr 14, 2019 6:43 am
by Lestevenie
Hi !
It's my first post and I have a question :
If i have a condition in a program (for exemple a booleean : 1 if it's "yes") on A :
for exemple if A>10 ,i =1 and else i=0.

Can I do ? :

38 0
39 STO "i"
40 RCL "Achar"
41 10
42 X<Y?
43 XEQ B
after i use my condtion...(for exemple in a formula)
and then at the end of program:

92 LBL B
93 1
94 STO "i"

Because it doesn't work for each condition I have (I have 4 condition like this in a formula).
Could you help me ?
You understood I'm a beginner in the use of this language

Thank you ,

Alexandre,

Re: A problem of Conditions

Posted: Sun Apr 14, 2019 10:28 am
by mezoganet
Kind of ludicrous question...

Tell us more as we can’t see what’s your problem...

Re: A problem of Conditions

Posted: Sun Apr 14, 2019 10:30 am
by grsbanks
Hi there,

The comparison function X<Y? and family do not compare variables, they compare values in the stack.

So, once you have run this bit:

Code: Select all

38 0
39 STO "i"
you have the value of "i" (zero) in X.

When you now do this:

Code: Select all

40 RCL "Achar"
that zero gets pushed up to Y in the stack and X now contains the value of the variable "Achar".

Code: Select all

41 10
This pushes your zero up to Z, the value of "Achar" up to Y and inserts the value 10 into X.

Code: Select all

42 X<Y?
43 XEQ B
"If X<Y then XEQ B"

Execution as of LBL B is started but only if 10 < "Achar".

Assuming the condition was met, you move here:

Code: Select all

92 LBL B
93 1
This pushes your original zero up to T, "Achar" up to Z, 10 up to Y and 1 into X.

Code: Select all

94 STO "i"
This stores 1 into "i" but leaves all the other stuff in the stack.

That explains what the functions actually do, but it doesn't solve your problem. Your problem is impossible to solve because "doesn't work" is not an accurate enough description of the problem to be able to help. What is actually happening that shouldn't be happening? What is not happening that should be happening? Have you tried any debugging by stepping through your program with SST?

Re: A problem of Conditions

Posted: Sun Apr 14, 2019 11:31 am
by dlachieze
Lestevenie wrote:
Sun Apr 14, 2019 6:43 am
If i have a condition in a program (for exemple a booleean : 1 if it's "yes") on A :
for exemple if A>10 ,i =1 and else i=0.
For boolean I would suggest using a flag instead of a variable :

Code: Select all

38 CF 00         /* clear flag 00
39 RCL "Achar"
40 10
41 X<Y?
42 SF 00         /* set flag 00
Then you can easily test if the flag is set or cleared with: FS?, FS?C, FC?, FC?C