Your basic code is valid -exit repeat will exit the current loop.
However, there are two problems with your script that may be impacting it.
The first is the use of 'delay'. This will essentially pause the entire script for the duration - in this case until the end of each play of the track. As a result you won't be able to stop mid-song, only at the end of a track. That may be OK, but it might also be confusing you if you expect it to stop mid-way.
The other issue is your condition:
if not (greenTime) then
Where are you setting this? There's nowhere within the loop that sets this variable therefore it will always have whatever value it had before the loop started. Again, that might be what you want, but I'm guessing you are expecting to change
greenTime at some point to trigger a premature exit, but this will never happen. You would need to set greenTime somewhere within the loop in order for it to have some effect.
So the big question remains as to exactly how you expect this script to work. What is 'greenTime' based on? Is it likely to change during the script's execution? or is it preset?