I want to define a set of values for a single variable. E.g.
singleDigit={0,1,2,3,4,5,6,7,8,9}
If the user gives 10 it should exit with an error.
How can this be achieved without using a loop, but an array instead?
I want to define a set of values for a single variable. E.g.
If the user gives 10 it should exit with an error. How can this be achieved without using a loop, but an array instead? |
|||||
|
If you want to store several values into a variable, that's where you'd use an array like:
Or
with And if you want to check whether a given string is among any of those values, you could define a function like:
(in Note that the comparison is lexical (as in 01 != 1). Do do numerical comparison, you'd use If you want to assign a pattern to a variable to match against some input, you'd use a scalar variable and use one of the 2 (3 with the
In the general case, for values other than single-character ones, you'd use:
And for patterns, you'd need the
Another approach with With
In
(note that with |
|||||||||
|
If only the numbers 0 through 9 are allowable as input, all you need is a simple IF statement.
|
|||
|