Hi,
how can you write this IF-Statement as a CASE-Statement?
DEF VAR i AS INT.
IF i < 0 THEN
MESSAGE "i < 0".
ELSE IF i = 0 THEN
MESSAGE "i = 0".
ELSE
MESSAGE "i > 0".
like following?? It doesn't work!!
CASE i:
WHEN < 0 THEN
MESSAGE "i < 0".
WHEN = 0 THEN
MESSAGE "i = 0".
WHEN > 0 THEN
MESSAGE "i > 0".
END CASE.
DISP i.
Thanks
Tom
your code doesn't work, beacuse you difine case i ( i like int) and when
The value in when instruction must be the same type like the case value:
Case MUST be constant value, therefore value will NOT work, how can the compiler compile the result if the value is not known?
CORRECT use would be;
CASE cVar:
WHEN 'SomeValue' THEN
DO:
/* block here */
END. /* SomeValue */
WHEN 'AnotherValue' THEN
DO:
/* block here */
END. /* AnotherValue */
END CASE. /* cVar */
CASE cVar:
The principal is the same for other datatypes. EG when wishing to case an integer
CASE iVar
WHEN inValue THEN /* eg WHEN 10 THEN*/
DO:
/* block here */
END. /* SomeValue */
WHEN DIFFERENTinValue THEN /* eg WHEN 23 THEN*/
DO:
/* block here */
END. /* AnotherValue */
END CASE. /* iVar */