Repository: TypeScript
Issue: for() not compiled correctly in 3.2.2
Labels: Bug,Domain: JS Emit

<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->
**TypeScript Version:**  3.2.2
not fixed with next == 3.3.0-dev.20190112

<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
**Search Terms:**
for( statement

**Code**

```ts
// tsc --target es5 --lib es2017

interface item {
  myKey: string;
  parent: string;
}
const xx: item[] = [
  {
    myKey: 'A',
    parent: ''
  }, {
    myKey: 'B',
    parent: 'A'
  }
];
const x = xx[1];
let y0key = 'none';
for (let y = x; y; y = xx.find(p => p.myKey === y.parent)) {
  console.log(JSON.stringify(y, null, 2));
  // if() added to prevent infinite loop
  if (y.myKey === y0key) {
    console.log('key not changed');
    break;
  }
  y0key = y.myKey;
}
console.log('outside loop');
```

**Expected behavior:**
The for() loop should visit xx[1] (key='B'), then its parent xx[0]  (key='A') and quit, because y becomes undefined.
Works correctly in typescript@3.1.6. 
Transpiled using
```cmd
tsc --target es5 --lib es2017
```
The generated code was:
```js
var xx = [
    {
        myKey: 'A',
        parent: ''
    }, {
        myKey: 'B',
        parent: 'A'
    }
];
var x = xx[1];
var y0key = 'none';
var _loop_1 = function (y) {
    console.log(JSON.stringify(y, null, 2));
    if (y.myKey === y0key) {
        console.log('key not changed');
        return "break";
    }
    y0key = y.myKey;
};
for (var y = x; y; y = xx.find(function (p) { return p.myKey === y.parent; })) {
    var state_1 = _loop_1(y);
    if (state_1 === "break")
        break;
}
console.log('outside loop');

```
**Actual behavior:**
The loop never quits without the if() statement. 
With 3.2.2 (or 3.3.0-dev.20190112), the output is:
```js
var xx = [
    {
        myKey: 'A',
        parent: ''
    }, {
        myKey: 'B',
        parent: 'A'
    }
];
var x = xx[1];
var y0key = 'none';
var _loop_1 = function (y) {
    if (inc_1)
        y = xx.find(function (p) { return p.myKey === y.parent; });
    else
        inc_1 = true;
    console.log(JSON.stringify(y, null, 2));
    if (y.myKey === y0key) {
        console.log('key not changed');
        return "break";
    }
    y0key = y.myKey;
};
var inc_1 = false;
for (var y = x; y;) {
    var state_1 = _loop_1(y);
    if (state_1 === "break")
        break;
}
console.log('outside loop');

```

You can see that the loop condition y is not checked after running the final expression (y=find()). As a result, the for loop now never quits without the if().

**Playground Link:** <!-- A link to a TypeScript Playground "Share" link which demonstrates this behavior -->
The link below uses alert() instead of console.log() and make the output move visible.
In TS3.1 the for loop shows B, A, and then quits. Then part of If() statement is never executed.
In TS3.2, mykey==='A' is visited twice, and caught by the if clause to break the infinite loop.

[playground link](http://www.typescriptlang.org/play/#src=%2F%2F%20tsc%20--target%20es5%20--lib%20es2017%0D%0A%0D%0Ainterface%20item%20%7B%0D%0A%20%20myKey%3A%20string%3B%0D%0A%20%20parent%3A%20string%3B%0D%0A%7D%0D%0Aconst%20xx%3A%20item%5B%5D%20%3D%20%5B%0D%0A%20%20%7B%0D%0A%20%20%20%20myKey%3A%20'A'%2C%0D%0A%20%20%20%20parent%3A%20''%0D%0A%20%20%7D%2C%20%7B%0D%0A%20%20%20%20myKey%3A%20'B'%2C%0D%0A%20%20%20%20parent%3A%20'A'%0D%0A%20%20%7D%0D%0A%5D%3B%0D%0Aconst%20x%20%3D%20xx%5B1%5D%3B%0D%0Alet%20y0key%20%3D%20'none'%3B%0D%0Afor%20(let%20y%20%3D%20x%3B%20y%3B%20y%20%3D%20xx.find(p%20%3D%3E%20p.myKey%20%3D%3D%3D%20y.parent))%20%7B%0D%0A%20%20alert(JSON.stringify(y%2C%20null%2C%202))%3B%0D%0A%20%20%2F%2F%20if()%20added%20to%20prevent%20infinite%20loop%0D%0A%20%20if%20(y.myKey%20%3D%3D%3D%20y0key)%20%7B%0D%0A%20%20%20%20alert('key%20not%20changed')%3B%0D%0A%20%20%20%20break%3B%0D%0A%20%20%7D%0D%0A%20%20y0key%20%3D%20y.myKey%3B%0D%0A%7D%0D%0Aalert('outside%20loop')%3B
)

**Related Issues:** <!-- Did you find other bugs that looked similar? -->
no