You're thinking colors are functions. Often, they are not.
On a switch loop, there is hot and switched-hot. There is no neutral.
Wiring methods
The primary wiring method used in homes is NM cable, or Romex. This cable is manufactured with ground, and two or more wires, in order of color: white, black, red, and blue. (And sometimes white with red stripe). You don't have any choice what colors come in Romex.. Because of that, you sometimes must use white as a hot.
A rare wiring method in homes is "loose wires in conduit". In this case, a pipe is laid between junction boxes, and individual wires are worked down the pipe. Electricians can choose any color of wire they please. I own 9 colors myself, because I like clarity. Also, they are not allowed to use white or gray as a hot wire in this wiring method.
Thinking about function
Really, most wires have a function.
- Equipment Safety Ground of course
- Neutral (the current return, and near ground potential).
- Always-hot, a wire expected to be energized at all times.
- Switched-hot, only hot when a switch is turned on, i.e. For a lamp.
- Messengers, in 3-way switch circuits, a pair where one or the other is energized
Wouldn't it be nice to use different colors for all these?
Color codes
In most of the world, ground is green, green/yellow, yellow/green, or bare.
In North America, neutrals must be white or gray.
Wires which are hot or may be energized hot can be any other color. (Black brown red orange yellow etc.)
In conduit, I use black for always-hot, red for switched-hot, yellow for messengers, etc. In Romex cable, I tape the conductors to match the colors I want.
Color codes collide with the reality of Romex
A switch loop needs 2 wires: hot and switched-hot (ideally black and red). There is no neutral on a switch loop**. So it's 1999, you run out to the truck to grab your /2 red-black-ground Romex... and guess what. That doesn't exist. You don't have a choice what colors come in Romex.
So you are forced to run a switch loop with black and white. The two wires are still hot and switched-hot. This is legal if you mark the white wire black (or other appropriate color). However most people don't bother marking wires in switch loops. This is why you are accustomed to seeing white in switch loops.
So here, what you are seeing is correct wire colors in use: black and black are legal for hot and switched-hot. You may be in conduit where they are not allowed to remark white wires.
** Normally neutral is omitted entirely from a switch loop. The new smart switches do need neutral. Because of this, there has been a change in the Electrical Code. Nothing changes in the conduit wiring method, because it's fairly easy to add a neutral wire. However in the NM/Romex wiring method, adding a wire to a cable is impossible, so new installations are required to use cable with an extra wire for neutral. White is reserved for neutral, usually switched-hot is red.