How to print the last value of a loop variable?

Okay , Thank you. I have started from trees and chained them ( with your help). The problem is I am trying to get a histogram with the no of peaks . In xaxis there is no of peaks and in yaxis there is count. But, when i am filling the histogram it is taking all the values of nfound (no of peak found variable) . I only want the final value of nfound .

I need the peaks with only good counts . The peak search function is giving that correctly. But when i am printing nfound it is showing all the values . Trying various option , can not find the correct one.

This example shows how to identify the peaks one by one (the first plot with red triangles)

Thank you.