Can I point out that when Gerrit said
Even though you declare f and t in your loop with a value of 0, this will not actually reset the values every single iteration, it only sets it to 0 and 2 initially. B
He was given you essentially the same answer as Mohammed.
(Please also see my note below about declaring variables at the top).