So I'm new to Eiffel programming and I'm trying to learn to write postconditions in the ensure
block of a feature
, in particular with writing loops.
So I tried this:
feature
-- sets the value of a particular in an array to x
foo (a: ARRAY[INTEGER]; target_val, x: INTEGER)
require
valid_target: 1 <= target_val and target_val <= a.count
do
a[target_val] := x
ensure
across
1 |..| a.count as i
all
across
1 |..| a.count as j
all
i.item /= j.item implies a[i.item] /= a[j.item]
end
end
end
But for some reason I get an unknown identifier for i
and j
. Does anyone know what causes this error and how I could fix it? Also, is there another alternative to using across ... as ... all ... end
in the ensure
block? Thanks so much in advance!
I don't know why you get a compilation error - I pasted your code and it compiles fine.
Incidentally, the Eiffel style guidelines say your comment should come AFTER the feature name and arguments, not before it.