The white wire on the switch loop is used to carry current from the source to the switch and it is marked with black tape or paint to label it as hot. The black on the switch loop runs from the top switch terminal to the top half of the receptacle. With this arrangement the top half of the duplex is controlled with the switch and the bottom half is always hot.
The always-hot wire from the receptacle is spliced to the black wire on the fixture cable, and to a pigtail that connects back to the hot terminal on the receptacle. At the light fixture box, the black is spliced to the black from the switch cable. At the switch box the black wire is connected to the bottom terminal on the new switch.
Another, more permanent, repair for an old doorbell circuit is to use a small ac adapter in place of the battery. Most people will have an AC adapter left after an old radio or similar device has long since died. Look for an output of 10 to 16 volts printed on the side of the adapter casing. Current ratings will typically be very low from these adapters, around 500mA, making them perfect to power the doorbell circuit. All that is needed is a conveniently located receptacle to plug the adapter in.
If you’re installing a new doorbell, a remote controlled device makes for the simplest installation and doesn’t require any of the circuitry illustrated on this page. All that’s required is to mount the button near an exterior door and the chimes in a convenient, central location inside the house. No need to run wires or splice into household circuits, fresh batteries are all that’s required.