OK, I understand what you are trying to do. Yes, you must leave the shift register uninitialized if you call the while loop multiple times and exit it immediately.
My code was meant to contain the shift register in the outermost loop of your program. To reduce clutter, you could also replace it with a feedback node.
With your coding style (This loop is inside the main loop, always exits immediately, and is only used to remember the fault state), you need to add a bit more logic, including a button to reset the state. (See image)