Everytime you get set to shove the throttle or throttles forward for the start of your take-off roll you should be thinking what if my engine quits. If it happens on the ground, easy decision, pull the throttle(s) off and try to stop on the runway. Once one is airborne things change, different choices depending on variables such as: altitude, single or twin, terrain, weather, and pilot skill. But one thing is certain, if you are in a single with a dying engine you will be a glider. I won't get into twin techniques for dealing with this, but will stick to a single.
Let us presume you are just off the runway 500 feet climbing and the engine starts sputtering. Just this scenario, although exact events are stiil not clear, happened last week at UZA ( Rock Hill, SC), an airport I know well as I used to keep my plane there. The plane a high performance turbo-charged single piloted by a pilot with slightly less than 400 hours. Apparently the pilot tried to make it back to the field but instead augered in, totally destroying both pilot and plane. The recommended procedure is to drop the nose to best glide speed as you look for a place to put the plane down. Trying to get back to the airport if you are too low will often lead to just what happened. Attention to airspeed is paramount as that is what is keeping the plane airborne. Too fast and you lose distance available, and too slow you stall. Every plane has a recommended glide speed as a function of gross weight. These speeds should be enblazened in your mind. Depending on the winds aloft, headwind vs. tailwind, the best glide speed will need some modification. With a headwind add 1/2 the headwind velocity to the best glide speed. For a tailwind decrease the best glide speed by about 10-20%.
When near the ground, fly the plane (glider) to a landing. Do not let it stall. Gear and flap positions need to be decided upon as both will affect your glide and how far and how fast you descend.
Ok, well in another scenario, you are at 8500 ft VFR over friendly terrain and the engine quits. So what do you do? Again, keep the plane flying at best glide speed to maximize the time aloft. Look around and choose your landing option early. You might do a circle to make sure there is no ideal spot to put down if you hadn't looked before. Once you have made your choice, set up a normal traffic pattern rather than trying to land straight in. So fly a downwind, base and final leg if able. This is something you are used to and familiarity should help. Whether to lower the gear in a retractable or not depends on how rough things are down there. Flaps will lower your stall speed and plane attitudes and sink rate will change. One author wrote about the aim point you need to establish in the windshield to help you know if you can make it to your destination. Pick a spot down where you are headed. If it starts rising in the windshield you won't make it, and your landing spot will be closer.
Finally as part of your recurrent training practice a simulated engine out from the downwind by bringing the engine to idle. If you don't trust yourself take an instructor with you.
Hopefully your engine will keep on purring, but if it quits you'll be ready to deal with it if you are prepared.