Or Check for the spells (once) when you first login and then use an event like
LEARNED_SPELL_IN_TAB to check again only when you learn something new.
What you are doing is telling your computer to run as hard and fast as it can until all conditions are met, so that's all it can do.
Edit: like jeruku said