fix issue KT-5234: 'when' statement in 'for', 'while', 'doWhile'

The title says it all. This commit doesn't break current tests for js-backend.