fix issue KT-5234 and KT-5058: 'when' statement in 'for', 'while', 'doWhile', add test for KT-5058