It has an infinite loop which I know is poor
All functional microcontroller code is an endless loop. Even if it is designed to only run once per bootup, it usually ends in an infinite loop. To make the micro actually turn off (as opposed to hibernate/sleep in a low frequency clock setting), you would need to control its reset pin and/or powersupply.... with another control circuit.
If you just want it to stop temporarily, while dev (say one of the outputs is connected to something like a large motor or something loud or annoying, and you are not finished coding), you can click the "MCLR button" at the top of the IDE interface to hold the MCLR pin high. This will hold the micro in reset, so long as MCLR is enabled.
Just because holding the micro in RESET will stop the internal clock, it still doesn't mean it will turn your circuit "off." This will put all the I/O pins into input/high impedance mode. Most of the time, you will have to define "off" (as per pin states) yourself, based on what is connected to the micro. Output hi/low might be necessary (or at least the lowest current draw) for your circuit. Hence, why nearly all code will "end" in an infinite loop after shutting off unneeded power consuming peripherals, slowing the clock, and defining pin in/out/pullups.
I'm not 100% positive about this, but I think the "end" command in say an IDE really just inserts an infinite loop of the "nop" command, in and of itself. Something akin to 1)turn off global interrupts 2)do nothing 3)goto 2.
If the micro could turn itself off in code, it would have no way to know when to start running, again. Sure, it can have bits to tell if the power was cycled or browned out. But in order to check those, it has to run. So you got a chicken and egg problem.
In assembly:
banksel INTCON
bcf INTCON, GIE
nop
goto $-1
or
banksel INTCON
bcf INTCON, GIE
Sleep
This is how you permanently stop your PIC micro in code, barring power cycle. If you don't have an ISR, you don't need to turn off global interrupts. The clock will still run, the processor will still process, and all your pins will retain state you last defined. Unless you use external control circuit, this is the best you can get.