Prepare First
Exploring any cave without a guide is very, very perilous. Make sure that people outside the cave know exactly where you enter the cave, that they have an expectation of when you'll contact them after emerging, and that they have a timetable for when to call for your search and rescue. Carry flashlights, plenty of spare batteries and a way to mark the floor showing your direction at every turn of a corner.
Breathe and Focus
If you end up getting lost, the most important thing you can do is also the hardest: Remain calm. Sit down, right where you are, and make a thorough assessment of your situation, including an inventory of the gear and food you're carrying. To prevent further disorientation, be sure to face the direction you came from when you sit down. Then focus on next steps. If the roof has not collapsed behind you, you know for certain that there is a way out. A calm, focused approach will help you find it.
Use Light Sources Intelligently
Use primary light sources, such as flashlights, first, and use them judiciously. Treat your battery life with the understanding that it is, in many ways, now your lifeline. If all your batteries die, use fire as your second light source. Wrap a piece of cloth around any stick you can find, and apply an oily fuel--such as butter, cheese, lipstick, lip balm, bug repellent, etc.--before lighting it. When that option is exhausted, sitting still in the darkness for half an hour will adjust your eyes to the light conditions as far as biologically possible. As a final resort, use the light from a mobile phone, a lighted watch, a GPS device, or other light-casting electronic device.
Stay Together
If you have a group with you when you get lost, it's vital to maintain a peaceful group dynamic. Have group members huddle and/or hold hands. Physical closeness preserves heat, reassures the group, and keeps everyone moving together. The moment when a group disperses in panic is the beginning of the end.
Find the Exit
If you have a lit candle or torch, keep it very still and watch the flame for the direction in which it flickers. That indicates the direction of airflow. Follow the airflow to find the exit, watching the flame at every turning point to choose a direction. Scratch your name, the time and your direction into the wall of the cave often at regular intervals. If that's impossible, leave identifiable arrangements of rocks or other available materials to mark your identity and direction. It's also helpful to leave a trail of nonessential items, starting at the exact point where you knew you were lost.