What is the difference between a market order and a limit order?

How do market orders and limit orders function differently, and when should each be used in trading?,