Sometime while loop does not work as we want even if condition is fulfilled. Action there is a basic function of a while that we are ignoring while applying conditionings.

How while loop is actually works

Basic syntax 

While(c ondition ) { Stateme nts . . . .  *Condit ion changing . . . .  } 

Somet imes , when we use while loop where conditioning variable is changing somewhere else like in "interrupt subroutine". But what happens there in subroutine we restore "program status register" after changing conditioning variable.

But, "while loop" check condition only when there is any changes in "program status register"  

(I noticed this in ATMEL STUDIO, AVR microcontroller ) 

There is three options to resolve this problem : 

1. Inside while loop, Change "program status register " (you can change even a single bit like SREG ^=(1<<SREG_C) ie. Carry bit ) 

2. In while loop, any statement that alter SREG register value . 

3. Or you can stop restoring SREG in "interrupt subroutine "