Actually, this probably shouldn't have compiled at all. AFAIK, Pascal comparison operators are supposed to only work on logical values, which the second and third clauses wouldn't be unless value3
There really isn't any way to compare a single value to a group of values in Pascal (or most other languages I can think of), at least not for arbitrary values. It is possible to use a set
membership in this manner with the union
operator if you are checking them against a fixed group of values known at compile time, but in general, comparisons are always one-to-one.
Without more details of the program (and possibly redesigning some of your data structures), I'd say you'll need to write the whole thing out:
- Pascal Code
if (value1 = value2) OR (value1 = value3) OR (value1 = value4) then
I realize this is a bit of a hassle, but for a small group of comparisons like this, it's not all that problematic.
As an aside, in most cases you want to use more descriptive variable names than 'valuen
' and so on. Names like those are just too easy to confuse with each other. If they really do form a sequence or group, then it probably makes more sense to put them together into an array:
FooArray: array [1..4] or FooType;
I should add that using an array may make a difference in the code above: it would be possible to use a loop of some sort to structure the test somehow. For the case given that would be overkill, but for longer comparisons against a large group of values, it can be very useful.
Of course, if the code you gave was just an example, and your actual variable names are more reasonable, feel free to ignore this.