function SwitchValueChanged(app, event)
value = app.Switch.Value;
This is a callback for Switch in APP Designer. When Switch is switched to On, the while loop is executed, and when Switch is switched to Off, the loop is terminated.
In fact, when switching to On, after the loop starts, switching the Switch state again will not enter the callback function, resulting in the failure to terminate the while loop.