Hi Rohit,
You can use 'drawnow' or one of its functional equivalents, such as 'pause(0)' inside of the while loop when it is running and button is unresponsive.
Adding this allows the system to register that the variable has updated, which subsequently breaks the loop.
Please refer the following documentation for drawnow function: https://www.mathworks.com/help/matlab/ref/drawnow.html