Using a commutator
To reverse the electrical direction of a coil, between a magnet, you can use a commutator.
When the wire coil is vertical there is an instance where the brushes switch the electrical direction of the current.
Below we have the wire coil which has switched electrical direction completely and the forces on the wire have reversed.
A continual spinning of the coil can occur.