Save variable between loops in Arduino IDE
The compiler sees that you read data each time through the loop, but never update it anywhere that can be directly reached. It therefore has optimized the code such that the initial value of data (0) is used instead of reading the actual value.

You can disable this optimization by declaring the variable volatile. This will force the compiler to generate code that reads the actual value each time instead.

volatile int data=0;