## A problem of Conditions

Discussion around the Swiss Micros DM42 calculator.
Lestevenie
Posts: 1
Joined: Sun Sep 09, 2018 12:03 pm

### A problem of Conditions

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,

mezoganet
Posts: 124
Joined: Tue Jan 22, 2019 1:54 pm
Location: Tours, France

### Re: A problem of Conditions

Kind of ludicrous question...

Tell us more as we can’t see what’s your problem...
HP33E, HP34C, HP41C, HP16C, HP28S, HP42S, HP48S, HP12C, HP35S, DM42, DM41L, DM15L, DM41X (SN#15) and HP3000 @ work during 18 yrs as IT Mgr

grsbanks
Posts: 975
Joined: Tue Apr 25, 2017 11:23 am
Location: Preston, Lancs, UK
Contact:

### Re: A problem of Conditions

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?
There are only 10 kinds of people in the world: those who understand binary and those who do not.

dlachieze
Posts: 220
Joined: Thu May 04, 2017 12:20 pm
Location: France

### Re: A problem of Conditions

Lestevenie wrote:
Sun Apr 14, 2019 8: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
DM42: 00425 - DM41X: β00066