core: fix processing 'if' at loop end