I am sorry but I don't understand your question at all, can you try to state it again precisely in other words?
The system does not get "confused", no matter what you do or how long your code/ while loop is running, provided that you don't mess up the code on your side.
You can set and reset the SHOW (and any other) flag as often as you like, you are just changing the value of a panel struct's number/ member. It does not get rendered immediately but at the end of the frame after all script execution and world rendering.
You can use the function layer_sort(void* element, var layer) to change the layer of any screen element at runtime.