case expression
mikea
Posts: 283
Hi, I'm trying to use case to test 3 values for not equal to x. If 4 is not equal to x, then dira[4]~ and so on. The compiler wants to see an expression term and highlights "<>". I'm not clear on what an expression term is. Thanks
case <> x 4: dira[4]~ 5: dira[5]~ 6: dira[6]~
Comments
That's a back to front case statement if I've seen one. Just supply the argument to case as x ( case x ) then that should work. However you could just as easily say:
if x <> 4 or x <> 5 or x <> 6
do this
But I see you probably need a case statement because of the different actions but I'm not getting the mixed up logic of this operation as if x <> 4 could just as easily be x <> 5 ..... oh well.
case X+Y
3:do that
4:or this
5:maybe this
other: do this for everything else
You can test ranges in the match expressions however, so you could do: However, that probably doesn't do what you were expecting either, as case stops at the first match. If x were 7 for instance, only pin 4 would be set to an input.
You could work around that by creating something like: or use if / thens as in: Or simply set every pin other than x in a range to an input, and leave x unchanged: dira := |< x & dira | dira &! %01110000
The case statement requires an 'expression term' it can evaluate to a single value.
If there's only three values you could use a series of if statements
Sandy