display dialog
返回一个字符串,而不是一个数字。您必须将字符串强制转换为整数
把它放在你的代码之前。
repeat
set answer2 to text returned of (display dialog “Enter a Number” default answer “0”)
try
set answer2 to answer2 as integer
exit repeat
on error
display dialog “I said: Enter a Number” buttons {“Give Up”, “Try again”} cancel button 1 default button 2
end try
end repeat
</code>
我建议使用
if
-
<code>
else if
</code>
-
<code>
end if
</code>
语法以获得更好的性能