Keep track of the previous result in a temporary variable.

Example work-flow:

Init. 2 variables, last val and current val.

Get current val, set last val equal to current val.
for i = 1, i <...