Hi everyone,
My code look something like this:
If a <= 100 then
d1 = d1 +1
elsif d1> = 150 then
d1 = d1-1
endif
I would like to have d1 within the interval 100;150. However, when d1 = 1, then the new d1 = d1 +1 = 2 and not 100.
Must be + or -1.
Thank you in advance.
It might help if you explain what you want to do with this code. Right now, the code is doing exactly what you've told it to do. It will check once whether a is between 100 and 150. If it's too low, it adds 1 to d1. If it's too high, it subtracts one. It will only do this once because it's in an if statement. So if d1 = 1, then the first part of the if statement is true, and it will add one to that.
Actually, on second look, did you mean to put a in line 1? Just a guess, but shouldn't it read:
If d1 <= 100 then
d1 = d1 +1
elseif d1> = 150 then
d1 = d1-1
endif
If you want to always keep d1 between 100 and 150 then you could do this:
If d1 <= 100 then
d1 = 100
elsif d1> = 150 then
d1 = 150
endif
That way if the value of d1 drops below 100 then it will automatically be set at 100 and vice versa.