change value of variable ?

If i have a variable that stores a value and i want to increase or decrease that value between say a min of 1 and max of 5 how do i code it, i have tried like this but have syntax errors.
Code:
let bo = bo + 1
if bo >5 then let bo = 5
let bo = bo - 1
if bo < 1 then bo = 1
 

premelec

Senior Member
IF ... THEN
[do something]
ENDIF

or ELSEIF

You are almost there! just a slight quirk that you can't do immediate THEN [Do something]...
 
thanks premelec i have figured it out and can now add it to my little program

Code:
let b0 = b0 + 1
if b0 >3 then
let b0 = 1
endif
 

hippy

Ex-Staff (retired)
Dont forget the MAX and MIN operators;

b0 = b0 + 1 MAX 5
b0 = b0 - 1 MIN 1
And, where the value may not initially be in the desired range, don't forget underflow and overflow avoidance...

b0 = b0 MAX 4 + 1
b0 = b0 MIN 2 - 1
 
Top