LPS-32059 Fix broken loop control flow