core: fix missing code after 'if' inside loop