I would expect the third comparison to be false but the comparison is always true? Why?
property notAvailable : "N/A"
set x to {1, 2, notAvailable}
repeat with ix in x
display dialog ix
if ix is not notAvailable then
display dialog "if: " & ix
end if
end repeat
In your repeat loop, “ix” is a reference to an item in a list, not the actual item itself. You need to coerce it into some item type or class, so it knows explicitly how to compare the two. Replacing…
if ix is not notAvailable then
… with …
if (ix as string) is not (notAvailable as string) then
For what it’s worth, here is a modification of your script that works:
property notAvailable : "N/A"
set x to {1, 2, notAvailable}
repeat with ix from 1 to count x
display dialog (item ix of x)
if item ix of x is not notAvailable then
display dialog "if: " & item ix of x
end if
end repeat
To get the value of the reference for comparison, use ‘contents of’:
property notAvailable : “N/A”
set x to {1, 2, notAvailable}
repeat with ix in x
display dialog ix
if (contents of ix) is not notAvailable then
display dialog "if: " & ix
end if
end repeat
Interestingly (to me anyway), contents of anItem is necessary when dealing with a repeat with anItem in listOfItems, but doesn’t seem to be necessary in repeat with k from 1 to count of listOfItems structures where the coercion seems to happen without explicit contents of.
Adam Bell, could you please refrain from posting using the color blue to highlight text? You’re using the same color to emphasize parts of your comments as the forum’s default link color. This is very confusing, and may lead some people to miss key information in links that people add inline in their posts. Your previous post has a handful of colorized sections that I assumed from their color were links. Using single or double quotes, bold, italic, or at least a different color not found in the forum would be more appropriate.