var now:int = 0;
var thn:int = 0;
function loop():void
{
// Change the number.
now = changingNumber;
if(now > thn)
{
trace("Got larger.");
}
else if(now < thn)
{
trace("Got smaller.");
}
else
{
trace("Maintained value.");
}
// Store the changed value for comparison on new loop() call.
// Notice how we do this AFTER 'now' has changed and we've compared it.
thn = now;
}
或者,你可以準備你的價值getter和setter和管理增加或減少在那裏。
// Properties.
var _now:int = 0;
var _thn:int = 0;
// Return the value of now.
function get now():int
{
return _now;
}
// Set a new value for now and determine if it's higher or lower.
function set now(value:int):void
{
_now = value;
// Comparison statements here as per above.
// ...
_thn = _now;
}
此方法將更有效,不需要循環。
如果序列既不增加也不減少,例如,輸出應該是什麼。 5 8 10 7 9 2?你想要整個序列的輸出還是隻輸出一對? – taskinoor 2012-07-05 09:36:44