core event-loop: define run by while and iterate