To keep it going, you have to add a little bit of energy on each cycle. In a pendulum clock the energy that keeps the pendulum moving comes from the spring. The pendulum gets a little push on each stroke to make up for the energy it loses to friction. See How Pendulum Clocks Work for details. An electronic oscillator works on the same principle.
Energy needs to move back and forth from one form to another for an oscillator to work.
You can make a very simple form of oscillator by connecting a capacitor and an inductor together. If you read How Capacitors Work and How Inductors Work , you will see that both capacitors and inductors store energy. A capacitor stores energy in the form of an electrostatic field in the capacitor, while an inductor uses a magnetic field. As it does, the inductor will create a magnetic field. Once the capacitor discharges, the inductor will try to keep the current in the circuit moving, so it will charge up the other plate of the capacitor.