Unfortunately, when I switch back to the Visual editor, WordPress changes my code. Although, the code is wrapped in a pre tag, the visual editor will still change or remove code. For instance, If I add ‘ < script > ‘ to my page, I had to resort to writing < script >, so the visual editor does not change it.
It recently occurred to me that if I create a post with a lot of code, rather than trying to trick the Visual editor, I remain in the HTML editor and never switch back into the Visual editor before I publish.
I hope this helps someone else writing code using WordPress.