Introduced a temporary variable to be one step ahead of iteration variable.