There's nothing wrong in general in having a for loop inside a while loop, but here the for loop serves no purpose whatsoever that I can tell. Look at what you're doing. You're checking to see if theta is greater or less than the previous time you checked it (actually the time before the previous time to be precise - check your shift registers).
If that's true, then you convert the true to a 1 and run the for loop 1 times. Why have a for loop if you know it'll always run once here? And then you take a timestamp then immediately take another timestamp and subtract them. You're not getting the elapsed time from when the changing values started.
Take a step back and try to plan out what you want to accomplish. You want to take a timestamp when the values start changing, and then take another timestamp as soon as they stop changing. I'll give you a hint: you might make use of another shift register which tracks whether you are still changing values in theta.
Jarrod S.
National Instruments