Back at the source, the white neutral wire is spliced to the white from the fixture cable and to a pigtail, back to the receptacle neutral terminal. At the fixture the white connects to the neutral terminal on the light. The hot terminal on the light is connected to the red wire from the switch loop cable and the other end is connected to the top terminal on the switch.
Here 3-wire cable serves a split receptacle. The bottom half of the receptacle is controlled by a switch and the top half is always-hot.
Above is a wiring diagram for a standard, 3-way lamp switch. This socket is used with a three way bulb containing 2 separate elements that are energized separately and then together as the switch knob is turned, for varying degrees of light.
This type of switch will be referred to as a 2 circuit lamp switch when shopping at home stores. Don’t mistake this for a three way switch (pictured below), the two do not function in the same way.